postgresqlHow do I administer a PostgreSQL database?
- First, you need to connect to the PostgreSQL database. To do this, you can use the
psql
command-line interface. For example, to connect to the database namedmydb
with userpostgres
, you can use the following command:
psql -U postgres mydb
- Once connected, you can use the
CREATE DATABASE
statement to create a new database. For example:
CREATE DATABASE mynewdb;
- You can use the
CREATE TABLE
statement to create tables in the database. For example:
CREATE TABLE users (
id serial primary key,
name text not null
);
- You can use the
INSERT INTO
statement to add data to the tables. For example:
INSERT INTO users (name) VALUES ('John');
- You can use the
SELECT
statement to query the data in the tables. For example:
SELECT * FROM users;
Output example
id | name
---+------
1 | John
- You can use the
ALTER TABLE
statement to modify the structure of a table. For example:
ALTER TABLE users ADD COLUMN email text;
- Finally, you can use the
DROP TABLE
statement 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 ZonedDateTime to store date and time information?
- How can I troubleshoot zero damaged pages in PostgreSQL?
- How do I parse XML data using PostgreSQL?
- How can I use PostgreSQL and ZFS snapshots together?
- How can I use PostgreSQL's "zero if null" feature?
- How can I use PostgreSQL with YAML?
- How can I use PostgreSQL with Zabbix?
- How can I retrieve data from PostgreSQL for yesterday's date?
- How do I install PostgreSQL and Zabbix on my system?
- How can I integrate PostgreSQL with Yii2?
See more codes...