barman PostgreSQL: FAILED - database

I am in the process of setting up a database backup system using Barman.
My database is a postgreSQL db.
When I run
barman check main-db
I get the following error:
PostgreSQL: FAILED
directories: OK
retention policy settings: OK
backup maximum age: FAILED (interval provided: 1 day, latest backup age: No available backups)
compression settings: OK
minimum redundancy requirements: OK (have 0 backups, expected at least 0)
ssh: OK (PostgreSQL server)
not in recovery: OK
The code I'm using in my barman.conf:
ssh_command = ssh postgres#10.0.0.XX
conninfo = host=10.0.0.XX user=YYYYYYY dbname=ZZZZZZZZ
retention_policy_mode = auto
retention_policy = RECOVERY WINDOW OF 7 days
wal_retention_policy = main
Any help would be greatly appreciated

The barman check output contains two errors, the first one is critical:
PostgreSQL: FAILED
It means that your barman user cannot connect with PostgreSQL using the credentials you provided in the conninfo parameter.
You can try it yourself by becoming the barman user and executing psql passing the content of conninfo as the only argument (it requires PostgreSQL clients installed on the server):
psql 'host=10.0.0.XX user=YYYYYYY dbname=ZZZZZZZZ'
It must connect to the target PostgreSQL servers without asking for any password.
The backup maximum age error is normal because you don't have any backup. However, it is not a blocking one, so it will not prevent you from taking your first backup.

This issue has now been resolved.
I solved this issue by ensuring that conninfo= had all the correct information. (Including password= field)

I think you deleted your barman user from PostgreSQL or you recreated that PostgreSQL cluster using postgresql-12-setup initdb command. Either you recover from old backup or you can do follow below steps.
postgres#pg$ createuser -s -P barman
postgres#pg$ psql
GRANT EXECUTE ON FUNCTION pg_start_backup(text, boolean, boolean) to barman;
GRANT EXECUTE ON FUNCTION pg_stop_backup() to barman;
GRANT EXECUTE ON FUNCTION pg_stop_backup(boolean, boolean) to barman;
GRANT EXECUTE ON FUNCTION pg_switch_wal() to barman;
GRANT EXECUTE ON FUNCTION pg_create_restore_point(text) to barman;
GRANT pg_read_all_settings TO barman;
GRANT pg_read_all_stats TO barman;
For streaming backup, you need to create streaming connection.
postgres#pg$ createuser -P --replication streaming_barman
Next update your pg_hba.conf file with your granted ip address.

Related

How to stop postgresql PGPOOL replication

I'm trying postgres database backup and restore. The access to postgres is through pgpool.
To achieve the back up I am following the official postgres pg_dumpall documentation.
Commands taken from postgres website: https://www.postgresql.org/docs/14/app-pg-dumpall.html
$ pg_dumpall > db.out
To reload database(s) from this file, you can use:
$ psql -f db.out postgres
The backup works fine.
However, when attempting to restore, I'm getting the following error because of replication feature enabled by pgpool.
psql:tmp/backup/postgresDump/pg_data.out:15: ERROR: database "xyz" is being accessed by other users
DETAIL: There is 1 other session using the database.
Here are the following ideas I tried by browsing other SO questions.
I tried to update active='f' in pg_catalog.pg_replication_slots view. It failed with the error below
DETAIL: Views that do not select from a single table or view are not automatically updatable.
HINT: To enable updating the view, provide an INSTEAD OF UPDATE trigger or an unconditional ON UPDATE DO INSTEAD rule.
List the process ids for the replication slot and used pg_terminate_backend along with the pid, followed by restore.
Command to terminate the replication slot
psql -U postgres -h pgpool.default.cluster.local -c "SELECT pg_terminate_backend(3402)"
pg_terminate_backend
----------------------
f
(1 row)
As per the second answer in this link, Postgresql - unable to drop database because of some auto connections to DB
I executed the terminate_backend command multiple times until it returned 0 results. Although this step was successful, restore failed with error saying
psql:tmp/postgresDump/pg_data.out:14: ERROR: database "xyz" is being accessed by other users
DETAIL: There is 1 other session using the database.
Looks like as soon as I drop a replication slot, the pgpool recreates the replication slot and establishes a connection for it.
Tried by dropping the replication_slot following the official documentation.
https://www.postgresql.org/docs/9.5/functions-admin.html
psql -U postgres -h pgpool.default.local -c "select pg_drop_replication_slot('repmgr_slot_1001');"
ERROR: replication slot "repmgr_slot_1001" is active for PID 3402
Any information on how to execute restore functionality through psql is highly appreciated.

disconnecting pgadmin's connection via bash

after registering the user in the postgres database(in ubuntu) we can execute some basic command like dropdb, createdb directly from the terminal to alter the database.
I basically was creating a shell script to renew the database. So, I thought doing this would suffice:
dropdb veganary_test && createdb veganary_test
as always, I was wrong. Since I had multiple connections to the database, db wouldn't drop. I also tried this:
psql <database_name> -c "SELECT pg_terminate_backend(pg_stat_activity.pid)
FROM pg_stat_activity
WHERE pg_stat_activity.datname = '<database_name>'
AND pid <> pg_backend_pid();"
and, yet it wasn't successful on disrupting pgadmin's connection. How can I disconnect every user connected to my <database_name> database from the terminal?(bash)
Upgrade to PostgreSQL v13 and use
dropdb --force veganary_test

SQL query to run data from two connection - Oracle and SQLServer connection

I'm using Oracle SQL developer. I need to create query to get data from two different connection, Oracle connection and SQLServer connection. How can I create link between the connections or how should I proceed?
I have tried to create database link but didn't succeed and received below error.
Create database link XXXX
connect to XXXX
identified by "XXXX"
using 'XXXX\XXXX';
Error starting at line : 1 in command -
Create database link xxxx
connect to xxxx
IDENTIFIED BY "xxxx"
using 'xxxx\xxxx'
Error report -
ORA-01031: insufficient privileges
01031. 00000 - "insufficient privileges"
*Cause: An attempt was made to perform a database operation without
the necessary privileges.
*Action: Ask your database administrator or designated security
administrator to grant you the necessary privileges
I get the same error message at any values so can the reason really be insufficient privileges? Is this even the correct way or is it even possible to use one query to get data from these two connections?

Connecting to newly created database after previous connection error

My application is periodically connecting to MyDatabase and performing a query.
I need to handle the case where the MyDatabase database does not already exist and needs to be created. What I am doing currently is each time I first connect to the master database and run something like this:
SELECT * FROM sysdatabases WHERE NAME='MyDatabase'
to determine whether MyDatabase exists. If it doesn't I create it and then proceed with connecting to MyDatabase and performing the query.
Opening a separate connection to the master database and performing a query each time seems unnecessary (even though the connections are pooled). Why can't I just connect to MyDatabase straight away? 99% of the time it will succeed and I can execute the queries. The 1% of times it fails I can detect MyDatabase is missing and create it at that point right?
But when I try this I hit a problem. If I attempt to connect to MyDatabase and it doesn't exist I get a SqlException
Cannot open database MyDatabase requested by the login. The login failed.
Fine. Great. I can catch any SqlException and then go off to the master database to determine MyDatabase does not exist and create it.
But after creating it, when I now try to connect to MyDatabase I immediately get the same error:
Cannot open database MyDatabase requested by the login. The login failed.
It looks like it isn't trying to connect again and instead is returning a cached result. If I wait 10 seconds after creating the database before attempting to connect to it, the connection succeeds.
My question is, is this caching expected (I guess so) and more importantly is there a best practice for dealing with this situation? Is there perhaps a cache clearance or timeout setting in the SqlConnection API I can use? I could implement my own timeout delay I think but I would like to know there isn't a better method I am missing.
I had exactly the same problem.
When I call the static SqlConnection.ClearAllPools() method before I try to open the newly created database, it works fine!

DB2 creating event monitor

I'd like to create event monitor on DB2 z/OS 9.2
i have spent a lot of time trying resolve this problem.
So i suggest this link: http://www.ibm.com/developerworks/data/library/techarticle/0303kolluru/0303kolluru.html
and trying to make this steps:
db2 => connect to dbname user username using password
db2 => update monitor switches using statement on
db2 => create event monitor rkmon for statements write to file '/tmp'
db2 => set event monitor rkmon state=1
but when I put command: create event monitor rkmon for statements write to file '/tmp'
Db2 throw me an error:
"DB2ADMIN" does not have the privilege to perform operation "CREATE EVENT MONITOR".. SQLCODE=-552, SQLSTATE=42502, DRIVER=3.58.81
so, then i try add some privilege to my db2admin user:
grant DBADM to db2admin
but get another error:
The name "DBADM" cannot be used because the specified identifier is reserved for system use.. SQLCODE=-707, SQLSTATE=42939, DRIVER=3.58.81
Now, I don't have any idea what shoould i do to resolve this problem.
Maybe, there is some othere way to logs sql queries sends to my db2 ?
(I develop some java apps using hibernate and db2, and sometimes quickest way to resolve some problem is see what sql queries is send to db).
Any ideas ?
Thanks
I think the "ON DATABASE" clause is mandatory in the GRANT statement. Try:
grant DBADM on database to user db2admin
GRANT (database authorities)
statement

Resources