This command is used to modify the attributes of a database, including the database name, owner, maximum number of connections, and object isolation attribute.
1 2 | ALTER DATABASE database_name [ [ WITH ] CONNECTION LIMIT connlimit ]; |
1 2 | ALTER DATABASE database_name RENAME TO new_name; |
If the database contains OBS multi-temperature tables, the database name cannot be changed.
1 2 | ALTER DATABASE database_name OWNER TO new_owner; |
1 2 | ALTER DATABASE database_name SET TABLESPACE new_tablespace; |
The current tablespaces cannot be changed to OBS tablespaces.
1 2 | ALTER DATABASE database_name SET configuration_parameter { { TO | = } { value | DEFAULT } | FROM CURRENT }; |
1 2 | ALTER DATABASE database_name RESET { configuration_parameter | ALL }; |
1 | ALTER DATABASE database_name [ WITH ] { ENABLE | DISABLE } PRIVATE OBJECT; |
Specifies the name of the database whose attributes are to be modified.
Value range: a string. It must comply with the naming convention.
Specifies the maximum number of concurrent connections that can be made to this database (excluding administrators' connections).
Value range: The value must be an integer, preferably between 1 and 50. The default value -1 indicates no restrictions.
Specifies the new name of a database.
Value range: a string. It must comply with the naming convention.
Specifies the new owner of a database.
Value range: a string indicating a valid user name
value
Sets a specified database session parameter. If the value is DEFAULT or RESET, the default setting is used in the new session. OFF closes the setting.
Value range: a string. It can be set to:
Sets the value based on the database connected to the current session.
Resets the specified database session parameter.
Resets all database session parameters.
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; |