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
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 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;"
I am setting up the Hortonworks Hadoop stack on a single instance RHEL 7 node. I am stuck in the part where I am setting up my ambari-server, using my PostgreSQL 9.2.15 database (not default, not embedded).
I also intend to use this same PostgreSQL instance for Hive and Oozie.
After following the instructions from here:
https://docs.hortonworks.com/HDPDocuments/Ambari-2.2.2.0/bk_ambari_reference_guide/content/_using_ambari_with_postgresql.html
https://docs.hortonworks.com/HDPDocuments/Ambari-2.2.2.0/bk_ambari_reference_guide/content/_using_hive_with_postgresql.html
https://docs.hortonworks.com/HDPDocuments/Ambari-2.2.2.0/bk_ambari_reference_guide/content/_using_oozie_with_postgresql.html
Here's how I named my database, user and schema:
ambari, ambari, ambari
hive, hive
oozie, oozie
This is how I configured my /var/lib/pgsql/data/pg_hba.conf file:
# Default
local all all peer
host all all 127.0.0.1/32 ident
# added settings
local all ambari md5
host all ambari 0.0.0.0/0 md5
host all ambari ::/0 md5
host oozie oozie <my-host-ip>/0 md5
host hive hive <my-host-ip>/0 md5
I run this, for Hive and Oozie:
$ ambari-server setup --jdbc-db=postgres --jdbc-driver=/usr/share/java/postgresql-jdbc.jar
Then for the actual Ambari setup
$ ambari-server setup
Enter advanced database configuration [y/n]? y
...
Enter choice (1): 4
Hostname (localhost): <my-fqdn-host-name>
Port (5432):
Database name (ambari):
Postgres schema (ambari):
Username (ambari):
Enter Database Password (bigdata) : <my-ambari-password>
However, I can't start the ambari-server, as I get this from /var/log/ambari-server/ambari-server.log on a number of lines:
Internal Exception: org.postgresql.util.PSQLException: FATAL: Ident authentication failed for user "ambari"
Although I am sure that my password is correct, and I can even connect using
$ psql -h <my-fqdn-host-name> -U ambari -d ambari -W
password: <my-ambari-password>
$ psql -h <my-host-ip> -U ambari -d ambari -W
password: <my-ambari-password>
However, I can't connect with
$ psql -h localhost -U ambari -d ambari -W
password: <my-ambari-password>
psql: FATAL: Ident authentication failed for user "ambari"
$ psql -h 127.0.0.1 -U ambari -d ambari -W
password: <my-ambari-password>
psql: FATAL: Ident authentication failed for user "ambari"
And I get the same error as what I get from /var/log/ambari-server/ambari-server.log. I suspect that ambari-server setup is connecting via localhost, that's why I get the same error.
Can you tell what's wrong with my configuration with Ambari and/or Postgres?
The problem is your pg_hba.conf file.
It is parsed from top to bottom, and the first matching line is used.
In your case, the line chosen is
host all all 127.0.0.1/32 ident
(you seem to connect from localhost) which is not what you want.
Either remove that line or move it to the end of the file.
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.
I want to remotely connect to a Postgres instance. I know we can do this using the psql command passing the hostname
I tried the following:
psql -U postgres -p 5432 -h hostname
I modified the /etc/postgresql/9.3/main/pg_hba.conf file on the target machine to allow remote connections by default
I added the following line to the file
host all all source_ip/32 trust
I restarted the cluster using
pg_ctlcluster 9.2 mycluster stop
pg_ctlcluster 9.2 mycluster start
However, when I try to connect from the source_ip, I still get the error
Is the server running on host "" and accepting TCP/IP connections on port 5432?
What am I doing wrong here?
I resolved this issue using below options:
Whitelist your DB host from your network team to make sure you have access to remote host
Install postgreSQL version 4 or above
Run below command:
psql -h <REMOTE HOST> -p <REMOTE PORT> -U <DB_USER> <DB_NAME>
psql -h <IP_Address> -p <port_no> -d <database_name> -U <DB_username> -W
-W option will prompt for password. For example:
psql -h 192.168.1.50 -p 5432 -d testdb -U testuser -W
I figured it out.
Had to set listen_addresses='*' in postgresql.conf to allow for incoming connections from any ip / all ip
Step Wise below
Opening the Port - Make sure the PSQL Port is open to all remote connections or connections from a specific set of IPs as per your requirement. PSQL, in general, runs at port 5432, and it is configurable, so expose relevant Port accordingly.
Update Remote Server PSQL Configuration - Set listen_addresses = '*' in postgresql.conf file, path in general is /etc/postgresql/psql_version/main/postgresql.conf
Connect remotely - psql -U <db_username> -h <IP_address> - in case psql is running on a port other than 5432 on the remote server, specify port by adding -p <port_number>
A little plus below -
In case the IP has been mapped to a domain name, you can connect by replacing <IP_address> with <host_name>. To do this, add a new connection rule in pg_hba.conf file
Note -
All above explained can cause security issues - best practice always is to either keep your psql port closed, or only allow a list of IPs to connect through the port.
Note that "ident" in pg_hba.conf requires a "ident server" to be running on the client.