> ## Documentation Index
> Fetch the complete documentation index at: https://docs.ahmadraza.in/llms.txt
> Use this file to discover all available pages before exploring further.

# Postgres

## Database Setup

```sh theme={null}
sudo -u postgres psql
```

### Create Database and User

```sql theme={null}
CREATE DATABASE code_monitor;
CREATE USER codemonitor WITH PASSWORD 'admin@123';
GRANT ALL PRIVILEGES ON DATABASE code_monitor TO codemonitor;
```

### User Management

```sql theme={null}
CREATE USER admin WITH PASSWORD 'admin';
ALTER USER admin WITH SUPERUSER;
```

### Show Databases

```sql theme={null}
\l
```

### Connect to a Specific Database

```sql theme={null}
\c your_database_name
```

### Show Tables in the Current Database

```sql theme={null}
\dt
```

### Export Database

```sh theme={null}
sudo -u postgres pg_dump -U postgres code_monitor > dbexport.pgsql
```
