$ sudo apt update && sudo apt install boxes -y
$ echo "this is linuxwave" | boxes
$ boxes -l
$ echo "this is linuxwave" | boxes -d unicornsay
$ man boxes
$ sudo apt update && sudo apt install boxes -y
$ echo "this is linuxwave" | boxes
$ boxes -l
$ echo "this is linuxwave" | boxes -d unicornsay
$ man boxes
$ sudo apt update && sudo apt install podman -y
[registries.search]registries = ['docker.io']
$ podman pull severalnines/clustercontrol
$ mkdir -p clustercontrol/{backups,cmon.d,cmonlib,datadir,prom-conf,prom-data,sshkey}
$ ssh-keygen -t ed25519Generating public/private ed25519 key pair.Enter file in which to save the key (/home/myuser/.ssh/id_ed25519): /home/myuser/clustercontrol/sshkey/id_ed25519Enter passphrase (empty for no passphrase):Enter same passphrase again:...
$ podman run -d --name clustercontrol \-h clustercontrol \-p 5000:80 \-p 5001:443 \-p 9443:9443 \-p 19501:19501 \-e DOCKER_HOST_ADDRESS=192.168.10.10 \-v $PWD/clustercontrol/cmon.d:/etc/cmon.d \-v $PWD/clustercontrol/datadir:/var/lib/mysql \-v $PWD/clustercontrol/sshkey:/root/.ssh \-v $PWD/clustercontrol/cmonlib:/var/lib/cmon \-v $PWD/clustercontrol/backups:/root/backups \-v $PWD/clustercontrol/prom-data:/var/lib/prometheus \-v $PWD/clustercontrol/prom-conf:/etc/prometheus \severalnines/clustercontrol
$ podman exec -it clustercontrol bash# s9s user --create --generate-key --controller="https://localhost:9501" --group=admins myuser# s9s user --change-password --new-password=anypassword myuser
Sometimes, we need to run psql command without entering the password, even though the account is protected with password. The usual situations are, when we are running the psql command in a script, or we have to constantly monitor the output of psql commands using watch. Here is the method on how to achieve that.
Create a .pgpass file inside the user's home directory who's going to access psql without password
$ touch ~/.pgpass
Follow below format to add the user's details into pgpass
hostname:port:database:username:password
$ echo "10.10.10.10:5432:mydatabase:myuser:mysuperlongpassword" > ~/.pgpass
We can also use wildcard, such as *. If you password contains ":" or "\", use "\" to escape them
$ echo "*:*:mydatabase:myuser:mysuperlongpassword" > ~/.pgpass
$ chmod 0600 ~/.pgpass
$ psql -h localhost -U myuser mydatabasepostgres=#
listen_addresses = '*'wal_level = replicamax_wal_senders = 3
$ sudo su - postgrespostgres@master:~$ createuser --replication -P replicauser
host replication replicauser 172.17.0.4/32 scram-sha-256
$ sudo systemctl restart postgresql
In slave node, do below steps:
- remove postgresql data directory which is /etc/postgresql/16/main (we can also rename it to save as a backup)
$ sudo su - postgres
postgres@slave:~$ rm -rf /etc/postgresql/16/main
- set a proper permission to the data directory
postgres@slave:~$ chmod 700 /etc/postgresql/16/main
- copy data from master (assuming master's ip address is 172.17.0.3)
postgres@slave:~$ pg_basebackup -h 172.17.0.3 -U replicauser -D /var/lib/postgresql/16/main/
- add standby.signal file inside postgresql data directory, to tell postgresql that this is a standby node
postgres@slave:~$ touch /var/lib/postgresql/16/main/standby.signal
- add below configuration (uncomment wherever necessary) /etc/postgresql/16/main/postgresql.conf
listen_addresses = '*'
hot_standby = on
primary_conninfo = 'host=172.17.0.3 port=5432 user=replicauser password=1'
- restart postgresql
$ sudo systemctl restart postgresql
Verify the replication is working
- in master, check pg_stat_replication table
$ sudo su - postgres
postgres=# select client_addr, state from pg_stat_replication where usename like 'replicauser';
- Check if walsender process is running in master
$ ps -ef | grep wal
- Check if walreceiver is running in slave
$ ps -ef | grep wal
-
We can also create a database in master, and verify that the same database appear in slave almost instantly .
$ sudo sh -c 'echo "deb https://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
$ wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
$ sudo apt update
$ sudo apt install postgresql-16 -y
$ sudo vi /etc/postgresql/16/main/postgresql.conf
listen_addresses = '*'
$ sudo systemctl start postgresql
$ sudo systemctl enable postgresql
$ sudo ufw allow 5432/tcp
$ sudo su - postgrespostgres@host:~$ psqlpostgres=# select version();