After the database is installed, a database named postgres is generated by default. You need to create your own database.
Syntax
·Create a database.
CREATE DATABASE database_name;
·View the database.
·Run \l to view the existing database.
\l
·Run \c + Database name to access the existing database.
\c dbname
·Modify the database.
ALTER DATABASE database_name RENAME TO new_name;
·Delete the database.
DROP DATABASE database_name ;
Parameter Description
·database_name
Specifies the name of the database to be created, modified, or deleted.
·new_name
Specifies the new name of a database.
Examples
·Create the db_tpcc database.
openGauss=# CREATE DATABASE db_tpcc;
If the following information is displayed, the creation is successful:
CREATE DATABASE
·Run \l to view the existing database.
·Create a database (this does not mean that the database is used). You need to specify that the created database is used. Run \c + Database name to access the db_tpcc database.
·Switch to the postgres database.
db_tpcc=# \c postgres
·Change the db_tpcc database name to tpcc.
openGauss=# ALTER DATABASE db_tpcc RENAME TO tpcc;
If the following information is displayed, the modification is successful:
ALTER DATABASE
·Delete the tpcc database.
openGauss=# DROP DATABASE tpcc;
If the following information is displayed, the deletion is successful:
DROP DATABASE
Top comments (0)