I Have a database rndb and created a new table myname_record which is created with owner "postgres" by default. In my program i should have change the owner to "rndb" but i missed it. Now i need to do it in console so i am login with command
psql=>psql -Urndb
and then changing the owner with following query
rndb=>ALTER TABLE public.myname_record OWNER to rndb;
but it is saying you must be owner to do this changes. I can understood because i am login through rndb it is giving this error. But how to make this changes actually.
You must own the table to use ALTER TABLE. To change the schema of a table, you must also have CREATE privilege on the new schema. To alter the owner, you must also be a direct or indirect member of the new owning role, and that role must have CREATE privilege on the table's schema.
To change the owner of a securable, use ALTER AUTHORIZATION. To change a schema, use ALTER SCHEMA.
You can't change the owner of a table. You can create a new table that is owned by NEW_USER , copy the data from the old table to the new table, drop the foreign key constraints that reference the old table, and create new foreign key constraints that reference the new table.
Select a role with superuser permission and try to change the owner of your table.
ALTER TABLE public.myname_record OWNER TO rndb;
You must connect as the current table owner, not the user you wish to change the table ownership to. Since that's postgres
:
psql -U postgres
or
sudo -u postgres psql
as required.
(Also, a superuser can always change table ownerships from anything to anything).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With