Only database system administrators or users granted with database creation permissions can create a database. For details about how to grant database creation permissions to a user, see User and Permission Overview.
CREATE DATABASE db_tpcds;
If the following information is displayed, the database has been created.
As said in Context, the template database template1 is copied by default to create a database. Its encoding format is SQL_ASCII. If the name of an object created in this database contains multiple-byte characters (such as Chinese characters) and exceeds the name length limit (63 bytes), the system truncates the name from the last byte instead of the last character. As a result, characters may be incomplete.
To resolve this problem, you need to:
If you fail to delete an object by specifying its name after truncation, specify its original name to delete it, or manually delete it from the system catalogs on each node.
You can also let CREATE DATABASE use template0 to create a database and specify new encoding and locale, for example, use UTF-8 as the default database encoding (server_encoding). For details, see the syntax in CREATE DATABASE.
You can run the show server_encoding command to view the current database encoding.
SELECT datname FROM pg_database;
You can execute the ALTER DATABASE statement to modify database attributes, such as the owner, name, and default configuration attributes.
ALTER DATABASE db_tpcds SET search_path TO pa_catalog,public; ALTER DATABASE
ALTER DATABASE db_tpcds SET TABLESPACE tpcds; ALTER DATABASE
ALTER DATABASE db_tpcds RENAME TO human_tpcds; ALTER DATABASE
You can execute the DROP DATABASE statement to delete a database. This command deletes the system directory in the database, as well as the database directory on the disk that stores data. Only the database owner or the system administrator can delete a database. A database accessed by users cannot be deleted. You need to connect to another database before deleting this database.
DROP DATABASE human_tpcds; DROP DATABASE