I have set up the master(192.168.1.10) and slave(192.168.1.11) postgresql. I got the error when login to the slave postgresql:
postgres#sonia-System-Product-Name:~$ psql
psql: FATAL: the database system is starting up
Transferring data by using:
psql -c "select pg_start_backup('initial_backup');"
rsync -cva --inplace --exclude=*pg_xlog* /data/dbs 192.168.1.11:/var/lib/postgresql/9.3/main/
psql -c "select pg_stop_backup();"
the postgresql.conf is
listen_addresses = 'localhost,192.168.1.10'
wal_level = 'hot_standby'
archive_mode = on
archive_command = 'cd .'
max_wal_senders = 3
hot_standby = on
I do not know why I can not login to slave postgresql. There is not problems with SSH connection.I have tried to restart service, but it did not work. please someone can help me out.
The problem sloved and share the solution. Thanks.
master server= 192.168.1.10
slave server = 192.168.1.20
Setup Master and slave postgresql
configuring Master server
ssh-keygen
ssh-copy-id the slave-ip-address
vi /etc/postgresql/9.3/main/postgresql.conf
listen_addresses = '*'
wal_level = hot_standby
max_wal_senders = 3
create replication role:
CREATE USER repuser WITH REPLICATION PASSWORD 'password';
configure the ip address on the master in order to the slave can have access to the master :
vi /etc/postgresql/9.3/main/pg_hba.conf
#rep
host replication repuser 192.168.1.20/24 md5
hostssl replication repuser 192.168.1.20/24 md5
configure the ip address on the slave server:
vi /etc/postgresql/9.3/main/pg_hba.conf
host replication repuser 192.168.1.10/24 md5
stop posgresql service on master server ( it is very import to do this step, otherwise, you will get log error on the slave sever when run psql.
/etc/init.d/postgresql stop
configuring the slave server
vi /etc/postgresql/9.3/main/postgresql.conf
listen_addresses = '*'
hot_standby = on
stop service and clean up data on Slave server
#/etc/init.d/postgresql stop
#cd /var/lib/postgresql/9.3/main/
#rm -rf *
Create recovery file
vi /var/lib/postgresql/9.3/main/recovery.conf
primary_conninfo = 'host=192.168.1.10 port=5432 user=repuser password=password'
standby_mode = on
copy data from the master to the slave database
rsync -av /var/lib/postgresql/9.3/main/* 192.168.1.20:/var/lib/postgresql/9.3/main/
start service on both slave and master
slave:~# /etc/init.d/postgresql start
master:~# /etc/init.d/postgresql start
verify the state of replication and run the following the command on the master sever
psql -x -c "select * from pg_stat_replication;"
Related
I'm deploying two servers with two PostgreSQL databases (one Primary and one Standby model). I have set the pg_hba.conf on my primary server to
host replication replicator <my standby ip addr> md5
and I've also enable the listen_address settings in postgresql.conf
listen_addresses = '*'
But when I was trying to run this command on my standby server
pg_basebackup -h <primary server ip addr> -D /var/lib/postgresql/12/main -U replicator -P -v -R -X stream -C -S node2
it returned this error message
pg_basebackup: error: could not connect to server: Connection refused
Is the server running on host "<primary ip addr>" and accepting
TCP/IP connections on port 5432
It is also verified that access to port 5432 has been enabled since I am able to connect to it from pgadmin via SSH.
my server is running on Ubuntu 20.04 with Postgresql version 12 installed
Is there anything I'm missing?
I am trying to crate master slave replication scenario in Postgress server.
I have create a master with the 5300 port and slave have the 5500
here is my postgresql.conf.
listen_addresses = '*'
port = 5300
wal_level = hot_standby
max_wal_senders = 3
wal_keep_segments = 8
synchronous_standby_names = 'slave1'
I have created pg_hba.conf with following configurations.
# "local" is for Unix domain socket connections only
local all all trust
# IPv4 local connections:
host all all 127.0.0.1/32 trust
# IPv6 local connections:
host all all ::1/128 trust
# Allow replication connections from localhost, by a user with the
# replication privilege.
local replication all trust
host replication all 127.0.0.1/32 trust
host replication all ::1/128 trust
host replication <database-user> 127.0.0.1/32 md5
host replication <database-user> 172.16.217.185/32 md5
host replication <database-user> 172.16.217.187/32 md5
Then I create cluster with the following command.
initdb
and then I start my master cluster with the following command.
bin/pg_ctl -w -l master/logs -o "-p 5300" start
and that command is running fine.
then I create the slave folder and copy all the master data in to it.
and past this folder to the slave side.
then after configuration I did create recovary.conf.
and put the following in it.
standby_mode = 'on'
primary_conninfo ='host=172.16.217.185 port=5300 user=<db_user> password=<Password> application_name=slave1'
then I start my slave.
pg_ctl -w -l slave/logs -o "-p 5500" start
that give me error when i see the slave/logs.
I see the error i have shared above.
FATAL: could not connect to the primary server: expected
authentication request from server, but received S
and remember I am running all the scenario in the VMFusion.
and one more thing I have try this with firewall enable/disable/allow
all them gives me the same so its not firewall that causing this error.
Thanks Advance.
Be sure that you have an archive named recovery.conf in your /data Slave directory, the file needs to content:
standby_mode = 'on'
primary_conninfo = 'host=192.168.x.x port=5432 user=rep password=xxxxxx'
trigger_file = '/tmp/postgresql.trigger.5432'
where 192.168.x.x you need to change with your Master Ip
and of course password is about user rep
I found the solution.
Actually this error occurs when more then one clusters are working on the same machine and when you run the following command.
pg_ctl -w -l slave/logs -o "-p 5500" start
The server got confused that which cluster should respond.
I resolve this issue while stopping all the clusters and starting the the concern one.
I'm trying to access to remote database from local machine.
Under su I use the following command:
psql -h remotehost.ru -U user -d test_psql
But without success: I try '\l' and see database-list, which mounted on local machine.
In pg_hba.conf (at local and remote machines):
host all user 0.0.0.0/0 md5
In postgresql.conf:
listen_addresses = '*'
I have updated my pg_hba on the master to this.
host loko replicator 10.0.2.15/32 trust
and created a user with this command
CREATE USER replicator REPLICATION LOGIN ENCRYPTED PASSWORD 'repl'
loko which is the databse on my master and replicator as the user.
and running this command on the slave
pg_basebackup -h x.x.x.x -D "C:\Program Files\PostgreSQL\9.4\data" -U
replicator -v -P --write-recovery-conf -X stream
results to
no pg_hba.conf entry for replication connection from host x.x.x.x.
user replicator, SSL off
Thanks a lot for any help. Im new to this so I don't have any idea whats wrong with this. I just followed a tutorial.
Change database loco to replication:
host replication replicator 10.0.2.15/32 trust
I just installed PostgreSQL 9.2 server on an EC2 AMI instance. However I am not able to connect to it from the command prompt.
Moreover I see two directories in /var/lib: pgsql9 and pgsql92. The data directory in pgsql92 is empty and hence it looks like pgsql9 is the one that is getting used.
[root#ip-172-31-56-103 etc]# psql
Password:
psql: FATAL: password authentication failed for user "root"
[root#ip-172-31-56-103 etc]# sudo su - postgres
-bash-4.2$ psql
Password:
psql: FATAL: password authentication failed for user "postgres"
-bash-4.2$ psql -U postgres
Password for user postgres:
psql: FATAL: password authentication failed for user "postgres"
-bash-4.2$
pg_hba.conf
# "local" is for Unix domain socket connections only
local all all md5
# IPv4 local connections:
host all all 127.0.0.1/32 md5
host all all 0.0.0.0/0 md5
# IPv6 local connections:
host all all ::1/128 ident
# Allow replication connections from localhost, by a user with the
# replication privilege.
#local replication postgres peer
#host replication postgres 127.0.0.1/32 ident
#host replication postgres ::1/128 ident
postgresql.conf
listen_addresses = '*'
To work out which PG install you are using: ps -ef | grep pgsql. You will see for sure which binary, data directory and conf file is being used to give you some comfort.
Have you changed the pg_hba.conf from the default? If so, did you reload it? Something like sudo service postgresql reload should do it, depending upon your OS.
You might want to change the IPv6 local connection to use md5 as well.
Try adding -h localhost or -h 127.0.0.1 to your psql command: e.g. psql -h localhost -U postgres.
Check your postgres password to be doubly / triply sure.
Otherwise, check out the specific docs for your OSs installation. Sometimes apt or yum repos do some additional security configuration for you.
Finally, worst case, change all the pg_hba.conf auth methods to trust, then restart the database, logon, change the postgres password, logout, change the auth methods to md5, reload and try to logon again.