2013-10-14 02:36:58 +00:00
|
|
|
---
|
2017-10-22 11:08:21 +00:00
|
|
|
title: PostgreSQL
|
2018-12-06 22:15:40 +00:00
|
|
|
category: Databases
|
2013-10-14 02:36:58 +00:00
|
|
|
---
|
|
|
|
|
2013-05-29 12:19:07 +00:00
|
|
|
### Console
|
|
|
|
|
2018-03-23 08:13:30 +00:00
|
|
|
$ psql #logs in to default database & default user
|
|
|
|
$ sudo -u <rolename:postgres> psql #logs in with a particular user
|
2013-05-29 12:19:07 +00:00
|
|
|
|
2023-03-14 04:40:29 +00:00
|
|
|
Replace anything within `<placeholder>` accordingly
|
|
|
|
|
2013-05-29 12:19:07 +00:00
|
|
|
### Commands
|
2012-10-11 08:13:19 +00:00
|
|
|
|
2018-03-23 08:13:30 +00:00
|
|
|
* Show roles: `\du`
|
2012-10-11 08:13:19 +00:00
|
|
|
* Show tables: `\dt`
|
|
|
|
* Show databases: `\l`
|
2018-03-23 08:13:30 +00:00
|
|
|
* Connect to a database: `\c <database>`
|
|
|
|
* Show columns of a table: `\d <table>` or `\d+ <table>`
|
|
|
|
* Quit: `\q`
|
2013-01-24 21:04:38 +00:00
|
|
|
|
2013-05-29 12:19:07 +00:00
|
|
|
### Creating database
|
|
|
|
|
|
|
|
$ createdb databasename
|