PostgreSQL PITR - postgresql

I have a master\server setup with pgpool and postgres 9.5. Both servers are running on centOS7.
I wanted to setup a point in time recovery with base backups every saturday, eliminating the old xlogs.
The server is archiving the xlogs with success on a external filesystem.
But when I try to execute the basebackup command it gives the following error:
pg_basebackup: could not connect to server: FATAL: database "replication" does not exist.

You seems to be missing the explicit HBA record for replication database, because specifying all does not covers the replication connections
host replication postgres 127.0.0.1/0 trust
The value replication specifies that the record matches if a
replication connection is requested (note that replication connections
do not specify any particular database). Otherwise, this is the name
of a specific PostgreSQL database.

Related

Postgres backup using pg_basebackup is failed

We are taking daily backup using pg_basebackup.
from two days ago it has been failing. we are using standalone environment.
error details
pg_basebackup: error: FATAL: number of requested standby connections exceeds max_wal_senders (currently 10)
FATAL: number of requested standby connections exceeds max_wal_senders (currently 10)
There are already too many replication connections to that database. Either terminate some, or increase max_wal_senders and restart PostgreSQL.
I would query pg_stat_activity to find the offending connections and use pg_terminate_backend to terminate them
You should extend your max_wal_replication slots in postgresql.conf. Here is a code to perform this change in linux terminal:
sed -i "s/max_replication_slots = 10/max_replication_slots = 20/g" postgresql.conf

How to exit out of database recovery mode (currently locked in read-only mode)

A slave database was set up some time ago for the purpose of backing up or replicating a remote database. However I can no longer write to the database using a Delphi based ETL (the ETL works for another database pair, but to date has never been used for this particular pair). The replication database was setup by somebody else who has since left the company. I am reasonably sure this has been setup as a replication database, however the employee who has since left told me that replication never worked for unrelated reasons. Using the ETL we can (using SQL queries) read from the one database, and write back to the replication database, Or should be able to, as it is currently read only.
I have tried:
Maintenance such as VACUUM
Attempt to drop tables and the entire database
Restore a full backup from the master database
None of these work, and I am told the database is read-only.
I have looked at postgresql.conf and see that hot_standby is checked, so I think (but am not 100% certain) that the database is in some sort of replication mode (I've never touched replication as supported by Postgres, so I wouldn't know).
I have checked permissions in pg_hba.conf and see there are some credentials in there for replication. I am not sure whether this activates "replication mode" for the database, or simply means these credentials are for replication only.
I have been through months worth of log files (This has not been working since our IT department upgraded the entire network about 5 months ago). I see the log file contents seen below, repeated over and over with nothing else for months. Note the IP address shown below is listed in the pg_hba.conf file, so credentials are valid.
The database is in recovery mode, as I have found by using:
select pg_is_in_recovery();
This explains to me why it's read only, but why can I not restore databases, or just simply dump the entire database and start again (it's a backup so losing/restoring it is not an issue)?
I was tempted to try modifying the recovery.conf file (which exists) but I read/believe that once recovery has been initiated (which in my case it has) modifying the file will have no effect.
I'm using a legacy version of Postgres: 9.2.9
Any help here would be greatly appreciated, as I have been working solidly on this for more than a day now.
Log File entry (sample):
FATAL: could not connect to the primary server:
FATAL: no pg_hba.conf entry for replication connection from host "192.168.20.2", user "postgres", SSL off
FATAL: could not connect to the primary server: server closed the connection unexpectedly
This probably means the server terminated abnormally before or while processing the request.
A couple of options would work for me:
Convert the database from being a read-only replication database, to a standard read/write database or
Dump/drop the entire database so I can create a new one with write capabilities.
It looks like the two database clusters have been set up for replication, but configuration changes on one of the machines broke the replication (changed pg_hba.conf on the primary, changed IP addresses, …).
Here is the way to your desired solutions:
Bringing the standby out of recovery mode: Run
/path/to/pg_ctl promote -D /path/to/data/directory
on the standby as operating system user postgres.
Nuking the standby: Remove the data directory on the standby with rm -rf (or the equivalent on your operating system). Kill all PostgreSQL processes.
Then use initdb to create a new database cluster in the same location.

WAL level not sufficient for making an online backup

I have tried to do database replication in linux 7.0 red hat using postgresql.
I refered this URL for Confuring http://blog.terminal.com/postgresql-replication-and-backup-methods/ I completed the the steps upto this step
Configuring the slave server
but the step
Initial replication
when I executed this command in Master
-bash-4.2$ psql -c "select pg_start_backup('initial_backup');"
I got Error Like this
ERROR: WAL level not sufficient for making an online backup
HINT: wal_level must be set to "archive" or "hot_standby" at server start.
So kindly let me know where we are wrong.
On your master PostgreSQL server's configuration file <PG_DATA>/postgresql.conf there is parameter called wal_level it should be set to either "archive" or "hot_standby"
Both said to postgres to keep WAL segmetnts for replication server. The difference between the two is rather simple:
"hot_standby" means that your replication server will allow connections for SELECT statements
"archive" means you don't want that possibility.
More to read in this tutorial on streaming replication
Also keep in mind that change of wal_level property needs server restart to take an effect.

pgAdmin connection error to pgpool

I'm using pgAdmin III to manage my database from client. I have a master and a slave postgreSQL running in streaming replication mode. There's another pgpool server in front of them to do connection pooling and load-balancing.
When I was connection pgAdmin to pgpool, I got:
Error connecting to the server: ERROR: unable to read message kind
DETAIL: kind does not match between master(52) slot[1] (45)
I had no problem connecting to it before, but somehow pgpool died and I restarted it, and then this error popped up out of no where.
The pgpool and postgreSQL servers are running well. I can access them with psql -h hostname database user. The app server can also connect to it and the web app is running as usually. I just cannot access it from pgAdmin.
http://www.sraoss.jp/pipermail/pgpool-general/2012-March/000297.html
In short: max_connections is exceeded on postgres cluster.
What I assume has happened - you restarted pgpool and it opened new connections to postgres, while old ones left in idle or idle in transaction (depending on timeout). So after restarting pgpool it consumed double amount of num_init_children and reached actual allowed maximum.
Killing old (before restart) pgpool connections should fix it. Try pg_terminate_backend(pid) run on postgres in order to do it. Also be carefull to kill right connections. At least check
select pid,query, client_address
from pg_stat_activity where now()-query_start > '1 day'::interval
or alike to catch only zombies

Sqlalchemy and pgpool-II - OperationalError

Today I set up pgpool-II on one of my company servers for database replication purposes and I'm trying to connect to it from my application located on another server. Previously it connected to database on the same server where pgpool is now installed without problems - I just needed to provide something like this link in config file:
database: postgresql://user:password#host:port/db_name
I have changed port to the one on which pgpool listens for connections and provided user and password from pcp.conf, but then I get a list of errors after starting app, all of them of the same type:
OperationalError: (OperationalError) unable to open database file None None
Doesn't matter if I'm authenticating as postgresql or pgpool user and if I provide md5 encrypted or plaintext password, errors are the same. How can I properly connect to my database then?
Problem solved days ago, needed to change administrative database in pgpool config from "template1" to "postgres". IDK why it doesn't default to that.