ALTER DATABASE

Function

Modifies the attributes of a database, including the database name, owner, maximum number of connections, and object isolation attributes.

Important Notes

Syntax

Parameter Description

  • Modifies the default tablespace of a database by moving all the tables or indexes from the old tablespace to the new one. This operation does not affect the tables or indexes in other non-default tablespaces.
  • The modified database session parameter values will take effect in the next session.

Example:

Set the maximum number of connections to database music to 10:

1
ALTER DATABASE music CONNECTION LIMIT= 10;

Change the database name from music to music1.

1
ALTER DATABASE music RENAME TO music1;

Change the owner of database music1 to tom:

1
ALTER DATABASE music1 OWNER TO tom;

Set the tablespace of database music1 to PG_DEFAULT:

1
ALTER DATABASE music1 SET TABLESPACE PG_DEFAULT;

Disable the default index scan on the music1 database.

1
ALTER DATABASE music1 SET enable_indexscan TO off;

Reset parameter enable_indexscan:

1
ALTER DATABASE music1 RESET enable_indexscan;

Links

CREATE DATABASE, DROP DATABASE