diff --git a/postgresql.md b/postgresql.md index 0debd9e0a18..de486da931b 100644 --- a/postgresql.md +++ b/postgresql.md @@ -1,25 +1,39 @@ --- title: PostgreSQL -category: Databases layout: 2017/sheet + +category: Databases +updated: 2024-01-15 +intro: | + PostgreSQL is a powerful, open source object-relational database system. + It provides the `psql` command line tool for interacting with its database. --- -### Console +### Create Database + +```shell +createdb +``` - $ psql #logs in to default database & default user - $ sudo -u psql #logs in with a particular user +### Query Database -Replace anything within `` accordingly +```shell +psql --no-align --tuples-only --command="SELECT * FROM " # Useful for scripting +psql -Atc "SELECT * FROM
" # short version of above +``` -### Commands +### Login to Database - * Show roles: `\du` - * Show tables: `\dt` - * Show databases: `\l` - * Connect to a database: `\c ` - * Show columns of a table: `\d
` or `\d+
` - * Quit: `\q` +```shell +psql # logs in to default database & default user +sudo -u psql # logs in with a particular user +``` -### Creating database +#### Commands - $ createdb databasename +* Show roles: `\du` +* Show tables: `\dt` +* Show databases: `\l` +* Connect to a database: `\c ` +* Show columns of a table: `\d
` or `\d+
` +* Quit: `\q` diff --git a/psql.md b/psql.md new file mode 100644 index 00000000000..dbd73d183dc --- /dev/null +++ b/psql.md @@ -0,0 +1,6 @@ +# redirect to postgresql.md +--- +title: PSQL +category: Hidden +redirect_to: /postgresql.md +---