# PostgreSQL

* [Info](/db/pgsql.md#info)
* [Config](/db/pgsql.md#config)
* [pgadmin](/db/pgsql.md#pgadmin)
* [Commands](/db/pgsql.md#commands)
* [user](/db/pgsql.md#user)
* [db](/db/pgsql.md#db)

## Info

```
SELECT version();
SELECT now();
```

## Config

<https://www.postgresql.org/docs/current/static/runtime-config-file-locations.html>

```
SHOW config_file;       -- /var/lib/postgresql/data/postgresql.conf
SHOW data_directory;    -- /var/lib/postgresql/data
SHOW hba_file;          -- /var/lib/postgresql/data/pg_hba.conf
    -- host-based authentication
    -- https://www.postgresql.org/docs/current/static/auth-pg-hba-conf.html
SHOW ident_file;        -- /var/lib/postgresql/data/pg_ident.conf
    -- user name mapping: SYSTEM-USERNAME PG-USERNAME
SHOW external_pid_file;
```

## pgadmin

```
docker run -p 80:80 \
-e "PGADMIN_DEFAULT_EMAIL=user@domain.com" \
-e "PGADMIN_DEFAULT_PASSWORD=SuperSecret" \
-d dpage/pgadmin4
```

DB->'Schemas'->'public'->'Tables'->right click table->'View/Edit Data'->'All Rows'

## Commands

<https://www.postgresql.org/docs/current/static/app-psql.html>

## user

```
SELECT usename FROM pg_user;
CREATE USER fzinfz;
\password fzinfz
ALTER USER fzinfz WITH SUPERUSER;
\du
    -- list user/role
```

## db

```
CREATE database tutorial;
\c tutorial
psql -U postgres -h localhost -d tutorial
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://book.ferro.pro/db/pgsql.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
