# Base SQL

# PostgreSQL

## Replication
### Check from master
select * from pg_stat_replication;
### Check from slave
select * from pg_stat_wal_receiver;
## CentOS 7 
PostgreSQL, also known as Postgres, is a free and open-source relational database management system emphasizing extensibility and SQL compliance. 
### Installation
source : https://tecadmin.net/install-postgresql-11-on-centos/

sudo yum install https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm

yum install postgresql${version}-server

/usr/pgsql-${version}/bin/postgresql-${version}-setup initdb

systemctl enable postgresql-${version}.service
systemctl start postgresql-${version}.service

postgres=# \password postgres

### Upgrade
https://www.postgresql.org/docs/11/upgrading.html

#### Minor version
1) Stopper le service postgreSQL
```
$ systemctl stop postgresql-11.service
```
2) Faire un dump global
```
$ pg_dumpall > db.out
```
3) Upgrader la version de postgreSQL
```
yum install postgresql11-${MINOR_VERSION}
yum install postgresql11-server-11.11-1PGDG.rhel7

Show available minor version 
yum list postgresql11 --showduplicates
```
4) Initier la base de données
```
/usr/pgsql-${version}/bin/postgresql-${version}-setup initdb
```

5) Relancer le service
```
$ systemctl start postgresql-11.service
```
##### Effective MEP
```
service postgresql-11 stop
cp -fra /mnt/data1/pgsql /mnt/data1/pgsql-old-20220510
yum remove postgresql11
yum install postgresql11-11.11-1PGDG.rhel7 postgresql11-server-11.11-1PGDG.rhel7 postgresql11-contrib-11.11-1PGDG.rhel7
/usr/pgsql-11/bin/postgresql-11-setup initdb

service postgresql-11 start
```
#### Major version (WIP)

# MariaDB

## Install 
https://computingforgeeks.com/how-to-install-mariadb-on-centos-rhel-7/
## Binlog
https://smarttechways.com/2021/05/27/enable-disable-the-binary-log-in-mysql/


Check bin log is enabled (ON) or disabled (OFF)
```
mysql> show variables like 'log_bin';
```

Show the list of binary file created.
```
mysql> SHOW BINARY LOGS;
```

Enable the Binary Log in MySQL
```
--For enable, edit the my.ini file and enter following parameter
log-bin="RAC1-bin"
```

Disable the Binary log in MySQL
```
-- For disable the binary log, Edit the my.ini file
#log-bin="RAC1-bin"  --Comment the log-bin parameter
skip-log-bin   -- enter this in my.ini file and save and restart the mysql
```

# MySQL

## MySQL 8.0
* https://www.mysqltutorial.org/install-mysql-centos/
* https://www.mariuszantonik.com/2022/03/the-gpg-keys-listed-for-the-mysql-8-0-community-server-repository-are-already-installed-but-they-are-not-correct/