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 do I use PostgreSQL's XMLTABLE to parse XML data?
- How do I use PostgreSQL with Qt?
- How can Zalando use PostgreSQL to improve its software development?
- How can I retrieve data from PostgreSQL for yesterday's date?
- How can I extract the year from a PostgreSQL timestamp?
- How do I use PostgreSQL's XMIN and XMAX features?
- How can I use PostgreSQL XOR to compare two values?
- How do I set up PostgreSQL replication?
- How can I view my PostgreSQL query history?
- How can I use PostgreSQL and ZFS snapshots together?
See more codes...