Wednesday, 25 March 2020

pg_dump: [archiver (db)] query was: LOCK TABLE

While performing backup using pg_dump with database user fails with error as below :


-bash-4.1$ pg_dump -U admin1 -W -F t nexaprd > var/lib/pgsql/nexa_prd_backup.tar
Password:
pg_dump: [archiver (db)] query failed: ERROR:  permission denied for relation company
pg_dump: [archiver (db)] query was: LOCK TABLE public.company IN ACCESS SHARE MODE



So it sounds like our problem might actually be that it is trying to dump a table admin1  don't have permission for.

The user which I'm performing the pg_dump as doesn't have permissions on the public schema.


Added permissions as below :

nexaprd=# GRANT USAGE ON SCHEMA public TO admin1 ;
GRANT
nexaprd=# GRANT SELECT ON ALL TABLES IN SCHEMA public TO admin1 ;
GRANT
nexaprd=#\q


Initiated backup :


-bash-4.1$ pg_dump -U admin1 -W -F t nexaprd > var/lib/pgsql/nexa_prd_backup.tar
Password:
-bash-4.1$

-bash-4.1$ ls -ltr nexa_prd_backup.tar
-rw-r--r-- 1 postgres postgres 8704 Mar 25 12:05 nexa_prd_backup.tar
-bash-4.1$


pg_dump doesn't lock the entire database, it does get an explicit lock on all the tables it is going to dump, though. This lock is taken in "access share mode", which is the same lock level required by a SELECT statement: it's intended just to guard against one of the tables being dropped between it deciding which tables to dump and then getting the data.


No comments:

Post a Comment