---
# System prepended metadata

title: postgresql - basic usage
tags: [database, postgresql]

---

# postgresql - basic usage

###### tags: `postgresql` `database`

```
# login postgresql database
/usr/share/postgresql $ psql --username=<username>

/usr/share/postgresql $ psql --username=mattermost
psql (9.4.20)
Type "help" for help.
```

```
# list databases
mattermost-# \list
Or
mattermost-# \l
Or
mattermost-# select datname from pg_database;

# Show more details
mattermost-# \l+
```

```
# connect to a database
mattermost-# \connect <database name>

```

```
# show tables
mattermost-# \dt
```

```
# select sql
mattermost=# SELECT * FROM <table name>;
```

```
# describe a table
mattermost=# \d+ <table name>;
```