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 can I use PostgreSQL with YAML?
- How do I use PostgreSQL ZonedDateTime to store date and time information?
- How can I use PostgreSQL and ZFS snapshots together?
- How can I integrate PostgreSQL with Yii2?
- How can I use PostgreSQL XOR to compare two values?
- How do I use PostgreSQL and ZFS together?
- How do I set the PostgreSQL work_mem parameter?
- How can I extract the year from a PostgreSQL timestamp?
- How do I install and configure PostgreSQL on a Windows machine?
- How can I set a PostgreSQL interval to zero?
See more codes...