Skip to content

Instantly share code, notes, and snippets.

@rodo
Last active January 8, 2018 16:56
Show Gist options
  • Select an option

  • Save rodo/e2fff23da180390fbff0d34dbc72c460 to your computer and use it in GitHub Desktop.

Select an option

Save rodo/e2fff23da180390fbff0d34dbc72c460 to your computer and use it in GitHub Desktop.
Manage postgresql template
# our template database will be called template2
# as user foobar
$ createdb template2
$ psql -d template2 -c 'create table test (id integer)'
$ psql -d template2 -c '\d' # you see that the table is owned by foobar
# create a new db based on the template
$ createdb new -T template2 -O newuser
$ psql -d new -c 'REASSIGN OWNED BY foobar TO newuser'
$ psql -d new -c '\d' # the table test is owned by newuser
$ psql -l # show that the owner of template2 is now newuser
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment