PostgreSQL - Rename database PostgreSQL - Rename database postgresql postgresql

PostgreSQL - Rename database


Try not quoting the database name:

ALTER DATABASE people RENAME TO customers;

Also ensure that there are no other clients connected to the database at the time. Lastly, try posting the error message it returns so we can get a bit more information.


For future reference, you should be able to:

-- disconnect from the database to be renamed\c postgres-- force disconnect all other clients from the database to be renamedSELECT pg_terminate_backend( pid )FROM pg_stat_activityWHERE pid <> pg_backend_pid( )    AND datname = 'name of database';-- rename the database (it should now have zero clients)ALTER DATABASE "name of database" RENAME TO "new name of database";

Note that table pg_stat_activity column pid was named as procpid in versions prior to 9.2. So if your PostgreSQL version is lower than 9.2, use procpid instead of pid.


I just ran into this and below is what worked:

1) pgAdmin is one of the sessions. Use psql instead.
2) Stop the pgBouncer and/or scheduler services on Windows as these also create sessions