35 lines
No EOL
1.7 KiB
Markdown
35 lines
No EOL
1.7 KiB
Markdown
---
|
|
title: PostgreSQL
|
|
description: PostgreSQL server information
|
|
icon: simple/postgresql
|
|
---
|
|
|
|
## Databases
|
|
|
|
| Database | Address | Port | User |
|
|
| ----------- | ----------- | ---- | ----------- |
|
|
| discord-red | 10.10.10.50 | 5432 | discord_red |
|
|
| forgejo | 10.10.10.50 | 5432 | forgejo |
|
|
| postgres | 10.10.10.50 | 5432 | postgres |
|
|
***All passwords stored in KeePassXC database.***
|
|
|
|
## Cheatsheet
|
|
|
|
| Usage | Command
|
|
| :-------------------------------------------------------------|:-------------
|
|
| Open postgres with `postgres` user permission | `sudo -u postgres psql`
|
|
| Check Postgres version | `select version();`
|
|
| Show all users with permissions | `\du`
|
|
| List all databases | `\l`
|
|
| Create a database | `CREATE DATABASE _mydb_;`
|
|
| Create a user with a password | `CREATE USER _myuser_ WITH PASSWORD 'mypassword';`
|
|
| Grant all permission of a database to Postgres user | `GRANT ALL PRIVILEGES ON DATABASE _mydb_ TO _myuser_;`
|
|
| Set database owner | `ALTER DATABASE _mydb_ OWNER TO _myuser_;`
|
|
| Connect to a database | `\c _db_name_`
|
|
| Connect to a database as specific user | `\c _db_name_ _pg_user_`
|
|
| Switch back to default database | `\c postgres postgres`
|
|
| Create a table | `CREATE TABLE _table_name_;`
|
|
|
|
---
|
|
|
|
*Last Updated: August 2, 2025* |