Use the ALTER DATABASE command with the OWNER TO clause to alter the database owner: ALTER DATABASE db_name How to Alter Database Owners in Postgres? Note: Similarly, the IS_TEMPLATE and CONNECTION LIMIT parameters can be used to change the database attributes. ![]() The output clearly states that you can’t establish a connection with the “postgres_db”. Let’s execute the “\c” command followed by the respective database name to verify the working of the “ALLOW_CONNECTIONS” parameter: \c postgres_db The above query specifies a “ false” value for the “ ALLOW_CONNECTIONS” parameter so that no one can establish the connection with the “postgres_db” database: The following example demonstrates how to modify a database attribute in Postgres: ALTER DATABASE postgres_db To modify database attributes, you must be a superuser or database owner. Specifying -1 indicates no connection limit. CONNECTION LIMIT: It determines how many concurrent connections can be established with a particular database. ALLOW_CONNECTIONS: If the "false" value is specified, establishing a connection with the selected database will not be possible. While specifying “false” means only superusers or the database owner can clone the selected database. “true” indicates that the selected database can be cloned/copied by any user having CREATEDB rights. IS_TEMPLATE: the value of the stated parameter can be either true or false. Where the “option” parameter can be replaced with one of the following: Utilize the below syntax to modify the attributes of an already existing database via the ALTER DATABASE command: ALTER DATABASE db_name WITH option How to Alter Database Attributes in Postgres? The output clarifies that the selected database has been renamed to “postgres_db”. Let’s verify the database modification using the “\l” command: \l For this purpose, the ALTER DATABASE command will be executed as follows: ALTER DATABASE postgres_copy ![]() Suppose we want to rename a database named “postgres_copy” to “postgres_db”. ![]() To accomplish this task, you need to establish a connection with some other database.Įxample: Renaming a Database Via ALTER DATABASE Commandįirstly, execute the “\l” command to list the available databases: \l Moreover, the current database can’t be renamed in PostgreSQL. To rename a database, you must be a superuser or database owner with CREATEDB privileges. Utilize the below-provided syntax to rename an already existing database via the ALTER DATABASE command: ALTER DATABASE db_name RENAME TO modified_name This Postgres guide presents a detailed overview of the ALTER DATABASE command using suitable examples. For instance, the ALTER DATABASE command allows Postgres users to rename a database, modify the database attributes, change the database ownership, reset configuration parameters, etc. Postgres supports an ALTER DATABASE statement that assists us in modifying the already existing databases.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |