snippetMinor
Is there a way in PostgreSQL to set an default owner for all future create table statements in a session
Viewed 0 times
postgresqlownercreatealltablestatementswayfuturedefaultfor
Problem
We have a program that transfers cobol data (index files) to a database.
Until now we transferred the data to an oracle database.
In the beginning of the program I logged in with user
Then I created a table and the table owner was automatically
We recently have switched databases from Oracle to Postgres.
Here I log in as "postgres", then I switch to the "ink" schema with:
Then I create a table and the table owner automatically is
So this behavior is reverse.
What do I have to do in order to get the same behaviour as with the oracle database:
In my scenario the table owner should automatically be
It would be nice if I would not have to write
after each create table command.
Until now we transferred the data to an oracle database.
In the beginning of the program I logged in with user
sys and then I altered the current schema to ink. I did this in this way, because ink has no privileges to create a table. Then I created a table and the table owner was automatically
ink, not sys.We recently have switched databases from Oracle to Postgres.
Here I log in as "postgres", then I switch to the "ink" schema with:
set search_path to 'ink';Then I create a table and the table owner automatically is
postgres, not ink.So this behavior is reverse.
What do I have to do in order to get the same behaviour as with the oracle database:
In my scenario the table owner should automatically be
ink, not postgres.It would be nice if I would not have to write
ALTER TABLE ... OWNER TO ink;after each create table command.
Solution
Be warned: I'm relatively new to PostgreSQL and so I'm not sure if this is a good practice or not, but...
One way I can think this can be addressed is by executing a
This way, even if the tables are momentarily owned by the
One way I can think this can be addressed is by executing a
REASSIGN OWNED statement at the end of the process that has created all your objects in the database, like this:REASSIGN OWNED BY CURRENT_USER TO ink;This way, even if the tables are momentarily owned by the
postgres user, you'll see them owned by ink once the creation process ends.Code Snippets
REASSIGN OWNED BY CURRENT_USER TO ink;Context
StackExchange Database Administrators Q#137206, answer score: 6
Revisions (0)
No revisions yet.