ALTER DATABASE

Function

This command is used to modify the attributes of a database, including the database name, owner, maximum number of connections, and object isolation attribute.

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:

Create the example database testdb and user tom.

1
CREATE DATABASE testdb ENCODING 'UTF8' template = template0;
1
2
DROP USER IF EXISTS tom;
CREATE USER tom PASSWORD '{Password}';

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

1
ALTER DATABASE testdb CONNECTION LIMIT= 10;

Change the database name from testdbto testdb_1.

1
ALTER DATABASE testdb RENAME TO testdb_1;

Change the owner of database testdb_1 to tom:

1
ALTER DATABASE testdb_1 OWNER TO tom;

Set the tablespace of database music1 to PG_DEFAULT:

1
ALTER DATABASE testdb_1 SET TABLESPACE PG_DEFAULT;

Disable the default index scan on the testdb_1 database.

1
ALTER DATABASE testdb_1 SET enable_indexscan TO off;

Reset parameter enable_indexscan:

1
ALTER DATABASE testdb_1 RESET enable_indexscan;

Links

CREATE DATABASE, DROP DATABASE