postgresqlHow do I administer a PostgreSQL database?
- First, you need to connect to the PostgreSQL database. To do this, you can use the
psqlcommand-line interface. For example, to connect to the database namedmydbwith userpostgres, you can use the following command:
psql -U postgres mydb
- Once connected, you can use the
CREATE DATABASEstatement to create a new database. For example:
CREATE DATABASE mynewdb;
- You can use the
CREATE TABLEstatement to create tables in the database. For example:
CREATE TABLE users (
id serial primary key,
name text not null
);
- You can use the
INSERT INTOstatement to add data to the tables. For example:
INSERT INTO users (name) VALUES ('John');
- You can use the
SELECTstatement to query the data in the tables. For example:
SELECT * FROM users;
Output example
id | name
---+------
1 | John
- You can use the
ALTER TABLEstatement to modify the structure of a table. For example:
ALTER TABLE users ADD COLUMN email text;
- Finally, you can use the
DROP TABLEstatement to delete tables from the database. For example:
DROP TABLE users;
For more information on administering PostgreSQL databases, please see the PostgreSQL documentation.
More of Postgresql
- How can I troubleshoot zero damaged pages in PostgreSQL?
- How do I use PostgreSQL's XMIN and XMAX features?
- How can I monitor PostgreSQL performance using Zabbix?
- How can I integrate PostgreSQL with Yii2?
- How can I use PostgreSQL with YAML?
- How do I use PostgreSQL's XMLTABLE to parse XML data?
- How do I use PostgreSQL UNION to combine the results of two queries?
- How do I decide whether to use PostgreSQL VARCHAR or TEXT data types?
- How do I use PostgreSQL with Qt?
- How can I retrieve data from PostgreSQL for yesterday's date?
See more codes...