I have 2 DB servers: 10.1.1.49 - master and 10.1.1.68 - slave. First is prod and the second one is dev server respectively. I need to replicate data from prod server to dev server, also I need to able to write some data to dev server as well.
When I configure these server as master-slave replication is successful. But when I am switching off only read option and enabling read-write option in dev server 10.1.1.49, replication doesn't work anymore. Can you help with this issue? My configurations are below.
In master 10.1.1.49 (prod) server:
pg_hba.conf:
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all peer
# IPv4 local connections:
host all all 127.0.0.1/32 scram-sha-256
host all all 10.1.1.0/24 md5
# IPv6 local connections:
host all all ::1/128 scram-sha-256
# Allow replication connections from localhost, by a user with the
# replication privilege.
local replication all peer
host replication all 127.0.0.1/32 scram-sha-256
host replication all ::1/128 scram-sha-256
host replication postgres 10.1.1.68/24 md5
postgresql.conf:
listen_addresses = '*'
wal_level = hot_standby
archive_mode = on
archive_command = 'cd .'
max_wal_senders = 8
hot_standby = on
In slave 10.1.1.68 server (dev)
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all peer
# IPv4 local connections:
host all all 127.0.0.1/32 scram-sha-256
host all all 10.1.1.0/24 md5
# IPv6 local connections:
host all all ::1/128 scram-sha-256
# Allow replication connections from localhost, by a user with the
# replication privilege.
local replication all peer
host replication all 127.0.0.1/32 scram-sha-256
host replication all ::1/128 scram-sha-256
host replication postgres 10.1.1.49/24 md5
postgresql.conf:
listen_addresses = '*'
wal_level = hot_standby
archive_mode = on
archive_command = 'cd .'
max_wal_senders = 8
hot_standby = on
executed commands when copying data from master to slave server:
in slave server:
rm -rf data; mkdir data; chmod go-rwx data
pg_basebackup -P -R -X stream -c fast -h 10.1.1.49 -U postgres -D ./data
There is no way you can write to a streaming replication standby server. What you need is logical replication.
Related
I want to connect to a pgAdmin 4 database by a remote server. However, when I want to save the connection properties, I get the following message:
unable to connect to server: timeout expired
This the content of the "pg_hba.conf":
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all scram-sha-256
# IPv4 local connections:
host all all 127.0.0.1/32 scram-sha-256
# IPv6 local connections:
host all all ::1/128 scram-sha-256
# Allow replication connections from localhost, by a user with the
# replication privilege.
local replication all scram-sha-256
host replication all 127.0.0.1/32 scram-sha-256
host replication all ::1/128 scram-sha-256
listen_addresses in "postgresql.conf" is also set to '*'
What should I do to be able to connect to the server remotely?
I am trying to execute the following on a fresh Postgre started as a service on CentOS 7
psql -h localhost -p 5432 -U postgres -X -d postgres -f /home/user/Documents/test.sql
however i get this error :
psql: FATAL: Ident authentication failed for user "postgres"
my pg_hba.conf is defined as following:
# TYPE DATABASE USER ADDRESS METHOD
#remove-line-for-nolocal## "local" is for Unix domain socket connections only
#remove-line-for-nolocal#local all all #authmethodlocal#
# IPv4 local connections:
local all user peer
local all postgres 127.0.0.1/32 trust
host all all 127.0.0.1/32 trust
# IPv6 local connections:
host all all ::1/128 md5
# Allow replication connections from localhost, by a user with the
# replication privilege.
#remove-line-for-nolocal#local replication all #authmethodlocal#
host replication all 127.0.0.1/32 #authmethodhost#
host replication all ::1/128 #authmethodhost#
Why does the execution fail ?
I have created a docker image with playframework backend that connects to pgsql localhost database. It is running smoothly when I run it in my local machine but when I run it in docker I receive errors.
I want to connect the docker container to my posgresql localhost.
I have tried configuring postgresql.conf and pg_hba.conf to open the port 5432
pg_hba.conf
# TYPE DATABASE USER ADDRESS
METHOD
# "local" is for Unix domain socket connections only
local all all trust
# IPv4 local connections:
host all all 127.0.0.1/32 trust
host all all 192.168.1.0/24 trust
host all all 172.17.0.0/16 trust
host all all 0.0.0.0/0 md5
# IPv6 local connections:
host all all ::1/128 trust
host all all ::/0 md5
# 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 172.17.0.0/32 trust
host replication all ::1/128 trust
postgresql.conf
listen_addresses = '*'
# what IP address(es) to listen on;
# comma-separated list of addresses;
# defaults to 'localhost'; use '*' for all
# (change requires restart)
port = 5432
When running my playframework app. I am getting the error below
Caused by: com.zaxxer.hikari.pool.PoolInitializationException: Exception during pool initialization
Caused by: org.postgresql.util.PSQLException: The connection attempt failed.
On a side note, postgresql is installed using brew, running correctly can access database using pgadmin4.
I get this below error while trying to set up BDR when both the nodes are on different hosts.
SELECT bdr.bdr_group_join(local_node_name := 'node2',node_external_dsn := 'port=5599 dbname=bdrdemo host=<ip of node2> user=postgres', join_using_dsn := 'port=5432 dbname=bdrdemo host=<ip of node1> user=postgres');
ERROR: establish BDR: FATAL: no pg_hba.conf entry for replication connection from host "[local]", user "postgres"
Both the hosts have a pg_hba.conf like:
# "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 postgres trust
host replication postgres 127.0.0.1/32 trust
host replication postgres ::1/128 trust
host all all 0.0.0.0/0 trust
host all all ::/0 trust
host replication postgres 0.0.0.0/0 trust
host replication postgres ::/0 trust
Changes to postgresql.conf
listen_adresses = '*'
shared_preload_libraries = 'bdr'
wal_level = 'logical'
track_commit_timestamp = on
max_connections = 100
max_wal_senders = 10
max_replication_slots = 10
max_worker_processes = 10
What has gone wrong here?
I am trying to setup pgAdmin on a new macbook. I am in the process of setting up a local server but keep getting the error:
Error connecting to the server: FATAL: role "postgres" does not exist
Here are my settings:
And here are the contents of my pg_hba.conf file:
# TYPE DATABASE USER ADDRESS METHOD
# "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 abc1234 trust
#host replication abc1234 127.0.0.1/32 trust
#host replication abc1234 ::1/128 trust
host all all localhost trust
host all all 192.168.1.0/24 trust
Can someone help?
Thanks in advance!
This error message is telling you that the postgres role, which is the usual "superuser" in a postgresql installation, does not exist.
In this case, it seems that the cluster has been installed using a local user as the superuser:
$ ls -ld /usr/local/var/postgres
drwx------ 30 abc1234 admin 1020 May 29 20:46 /usr/local/var/postgres
In which case we can probably login using:
$ psql -U abc1234 postgres