diff --git a/content/posts/2018-06.md b/content/posts/2018-06.md index 12a6d2303..9ccca5ae0 100644 --- a/content/posts/2018-06.md +++ b/content/posts/2018-06.md @@ -227,4 +227,20 @@ UPDATE 1 - I uploaded the twenty-four reports to the IWMI Reports collection: https://cgspace.cgiar.org/handle/10568/36188 - I uploaded the seventy-six book chapters to the IWMI Book Chapters collection: https://cgspace.cgiar.org/handle/10568/36178 +## 2018-06-24 + +- I was restoring a PostgreSQL dump on my test machine and found a way to restore the CGSpace dump as the `postgres` user, but have the owner of the schema be the `dspacetest` user: + +``` +$ dropdb -h localhost -U postgres dspacetest +$ createdb -h localhost -U postgres -O dspacetest --encoding=UNICODE dspacetest +$ psql -h localhost -U postgres dspacetest -c 'alter user dspacetest superuser;' +$ pg_restore -h localhost -U postgres -d dspacetest -O --role=dspacetest -W -h localhost /tmp/cgspace_2018-06-24.backup +$ psql -h localhost -U postgres dspacetest -c 'alter user dspacetest nosuperuser;' +``` + +- The `-O` option to `pg_restore` makes the import process ignore ownership specified in the dump itself, and instead makes the schema owned by the user doing the restore +- I always prefer to use the `postgres` user locally because it's just easier than remembering the `dspacetest` user's password, but then I couldn't figure out why the resulting schema was owned by `postgres` +- So with this you connect as the `postgres` superuser and then switch roles to `dspacetest` (also, make sure this user has `superuser` privileges before the restore) + diff --git a/docs/2018-06/index.html b/docs/2018-06/index.html index 2fdb5cdae..3e34d1467 100644 --- a/docs/2018-06/index.html +++ b/docs/2018-06/index.html @@ -41,7 +41,7 @@ sys 2m7.289s - + @@ -93,9 +93,9 @@ sys 2m7.289s "@type": "BlogPosting", "headline": "June, 2018", "url": "https://alanorth.github.io/cgspace-notes/2018-06/", - "wordCount": "1637", + "wordCount": "1814", "datePublished": "2018-06-04T19:49:54-07:00", - "dateModified": "2018-06-14T12:40:42+03:00", + "dateModified": "2018-06-14T14:46:09+03:00", "author": { "@type": "Person", "name": "Alan Orth" @@ -427,6 +427,25 @@ UPDATE 1
postgres
user, but have the owner of the schema be the dspacetest
user:$ dropdb -h localhost -U postgres dspacetest
+$ createdb -h localhost -U postgres -O dspacetest --encoding=UNICODE dspacetest
+$ psql -h localhost -U postgres dspacetest -c 'alter user dspacetest superuser;'
+$ pg_restore -h localhost -U postgres -d dspacetest -O --role=dspacetest -W -h localhost /tmp/cgspace_2018-06-24.backup
+$ psql -h localhost -U postgres dspacetest -c 'alter user dspacetest nosuperuser;'
+
+
+-O
option to pg_restore
makes the import process ignore ownership specified in the dump itself, and instead makes the schema owned by the user doing the restorepostgres
user locally because it’s just easier than remembering the dspacetest
user’s password, but then I couldn’t figure out why the resulting schema was owned by postgres
postgres
superuser and then switch roles to dspacetest
(also, make sure this user has superuser
privileges before the restore)