How to solve privileges issues when restore PostgreSQL Database

前端 未结 10 1975
Happy的楠姐
Happy的楠姐 2020-12-12 16:19

I have dumped a clean, no owner backup for Postgres Database with the command

pg_dump sample_database -O -c -U

Later, when I restore the databas

10条回答
  •  天涯浪人
    2020-12-12 16:50

    To solve the issue you must assign the proper ownership permissions. Try the below which should resolve all permission related issues for specific users but as stated in the comments this should not be used in production:

    root@server:/var/log/postgresql# sudo -u postgres psql
    psql (8.4.4)
    Type "help" for help.
    
    postgres=# \du
                   List of roles
        Role name    | Attributes  | Member of
    -----------------+-------------+-----------
         | Superuser   | {}
                     : Create DB
     postgres       | Superuser   | {}
                     : Create role
                     : Create DB
    
    postgres=# alter role  superuser;
    ALTER ROLE
    postgres=#
    

    So connect to the database under a Superuser account sudo -u postgres psql and execute a ALTER ROLE Superuser; statement.

    Keep in mind this is not the best solution on multi-site hosting server so take a look at assigning individual roles instead: https://www.postgresql.org/docs/current/static/sql-set-role.html and https://www.postgresql.org/docs/current/static/sql-alterrole.html.

提交回复
热议问题