pgschema icon indicating copy to clipboard operation
pgschema copied to clipboard

pgschema does not seem to work with ALTER DEFAULT PRIVILEGES

Open chcharlet opened this issue 9 months ago • 3 comments

When using ALTER DEFAULT PRIVILEGES (without specifying a FOR ROLE) and running with the embedded postgres, something goes wrong and pgschema wants to revoke default privileges on the postgres role and add them to a (non-existant) pgschema role.

Trying to solve this by making FOR ROLE postgres explicit doesn't work either, because then pgschema fails with "role postgres does not exist".

I can sort-of work around that by making the role explicit and running in an external planning database, but even there it seems to me I fail on the second run - though that might be another issue. Still looking into that.

chcharlet avatar Feb 20 '26 10:02 chcharlet

Please provide script

tianzhou avatar Feb 20 '26 15:02 tianzhou

Hey,

to replicate start up a new postgres container with pgschema installed (I am using postgres:17-alpine with pgschema 1.7.1) and initialize the database with this script: init.sql

Now run pgschema: pgschema apply --file /docker-entrypoint-initdb.d/init.sql --host localhost --user postgres --schema demo --db postgres - no change to the init file necessary.

For me, this fails with the error message Error: failed to apply desired state: failed to apply schema SQL to temporary schema pgschema_tmp_20260222_214130_c82ed209: ERROR: role "postgres" does not exist (SQLSTATE 42704)

chcharlet avatar Feb 22 '26 21:02 chcharlet

Have you been able to reproduce this? If you need further information I am happy to add more to my example.

chcharlet avatar Mar 04 '26 10:03 chcharlet