Skip to content

Instantly share code, notes, and snippets.

@davidkrisch
Last active February 3, 2024 20:05

Revisions

  1. davidkrisch revised this gist Feb 3, 2024. 1 changed file with 23 additions and 10 deletions.
    33 changes: 23 additions & 10 deletions postgres_wsl.md
    Original file line number Diff line number Diff line change
    @@ -15,30 +15,38 @@ sudo apt-get install postgres

    - https://wiki.debian.org/PostgreSql
    - Link contains location of config files, binaries, and data files
    - Debian has replaced pg_ctl with their own perl script pg_ctlcluster
    - Debian has replaced `pg_ctl` with their own perl script `pg_ctlcluster`

    - configs: /etc/postgresql/11/main/
    - binaries: /usr/lib/postgresql/11/bin # not on the PATH, contains pg_ctl
    - data: /var/lib/postgresql/11/main/ # owned by user postgres
    - logs: /var/log/postgresql/postgresql-11-main.log # tail as user david seems to work
    - configs: /etc/postgresql/16/main/
    - binaries: /usr/lib/postgresql/16/bin # not on the PATH, contains pg_ctl
    - data: /var/lib/postgresql/16/main/ # owned by user postgres
    - logs: /var/log/postgresql/postgresql-16-main.log # tail as user david seems to work

    ### Start the server

    First time only, create [unix_socket_directory](https://www.postgresql.org/docs/current/runtime-config-connection.html#GUC-UNIX-SOCKET-DIRECTORIES)

    Create unix_socket_directory [docs](https://www.postgresql.org/docs/current/runtime-config-connection.html#GUC-UNIX-SOCKET-DIRECTORIES)

    ```
    $ sudo mkdir /var/run/postgresql
    $ sudo chown postgres /var/run/postgresql
    ```

    The Debian way...

    As of January 27, 2024, The Art of Postgresql data is in Postgres 16
    so start it like this after creating the run directory that seems
    to get destroyed after restarting

    ```
    sudo -u postgres pg_ctlcluster --foreground 11 main start
    sudo -u postgres pg_ctlcluster --foreground 16 main start
    ```

    Postgres docs on starting the server
    https://www.postgresql.org/docs/11/server-start.html
    In another terminal `psql -p 5434` connects to database `david`.
    Use `set search_path <schema>` to explore f1db or chinook schemas.

    Postgres [docs](https://www.postgresql.org/docs/16/server-start.html) on starting the server

    ## Notes from first time setup

    ### Create a user

    @@ -83,3 +91,8 @@ GRANT ROLE
    postgres=# \q
    postgres@DAVID-PC:/mnt/d/a-curious-moon/curious_data$ exit
    ```

    ### Install Deps for TAOP

    1. sudo apt-get install postgresql-16-hll postgresql-16-ip4r
    2. Run `make` as postgres user
  2. davidkrisch revised this gist Jan 19, 2024. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion postgres_wsl.md
    Original file line number Diff line number Diff line change
    @@ -24,7 +24,7 @@ sudo apt-get install postgres

    ### Start the server

    First time only, create (unix_socket_directory)[https://www.postgresql.org/docs/current/runtime-config-connection.html#GUC-UNIX-SOCKET-DIRECTORIES]
    First time only, create [unix_socket_directory](https://www.postgresql.org/docs/current/runtime-config-connection.html#GUC-UNIX-SOCKET-DIRECTORIES)


    ```
  3. davidkrisch revised this gist Jan 19, 2024. 1 changed file with 9 additions and 1 deletion.
    10 changes: 9 additions & 1 deletion postgres_wsl.md
    Original file line number Diff line number Diff line change
    @@ -24,9 +24,17 @@ sudo apt-get install postgres

    ### Start the server

    First time only, create (unix_socket_directory)[https://www.postgresql.org/docs/current/runtime-config-connection.html#GUC-UNIX-SOCKET-DIRECTORIES]


    ```
    $ sudo mkdir /var/run/postgresql
    $ sudo chown postgres /var/run/postgresql
    ```

    The Debian way...
    ```
    sudo -u postgres pg_ctlcluster 11 main start
    sudo -u postgres pg_ctlcluster --foreground 11 main start
    ```

    Postgres docs on starting the server
  4. davidkrisch revised this gist Jan 19, 2024. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions postgres_wsl.md
    Original file line number Diff line number Diff line change
    @@ -25,7 +25,9 @@ sudo apt-get install postgres
    ### Start the server

    The Debian way...
    ```
    sudo -u postgres pg_ctlcluster 11 main start
    ```

    Postgres docs on starting the server
    https://www.postgresql.org/docs/11/server-start.html
  5. davidkrisch renamed this gist Jan 19, 2024. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  6. davidkrisch created this gist Jan 19, 2024.
    75 changes: 75 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,75 @@
    ## PostgreSQL on Debian buster in WSL

    ### Install

    First install Windows Terminal from the Microsoft Store on Windows 10
    https://docs.microsoft.com/en-us/windows/terminal/

    Then use that to install postgres in Debian WSL

    ```
    sudo apt-get install postgres
    ```

    ### Debian docs for postgresql

    - https://wiki.debian.org/PostgreSql
    - Link contains location of config files, binaries, and data files
    - Debian has replaced pg_ctl with their own perl script pg_ctlcluster

    - configs: /etc/postgresql/11/main/
    - binaries: /usr/lib/postgresql/11/bin # not on the PATH, contains pg_ctl
    - data: /var/lib/postgresql/11/main/ # owned by user postgres
    - logs: /var/log/postgresql/postgresql-11-main.log # tail as user david seems to work

    ### Start the server

    The Debian way...
    sudo -u postgres pg_ctlcluster 11 main start

    Postgres docs on starting the server
    https://www.postgresql.org/docs/11/server-start.html

    ### Create a user

    ```
    $ sudo su - postgres
    $ createuser --pwprompt david
    $ createdb -O david david_db
    $ exit
    ```

    ### Login

    ```
    psql -d david_db -h localhost -U david
    ```

    ### Login without a password

    ```
    echo 'localhost:5432:david_db:david:password' >> ~/.pgpass
    chmod 600 ~/.pgpass
    ```

    Now connect without entering a password

    ```
    psql -d david_db -h localhost -U david
    ```

    ### Allow COPY command for user David

    https://www.postgresql.org/docs/11/role-membership.html

    ```bash
    david@DAVID-PC:/mnt/d/a-curious-moon/curious_data$ sudo su postgres
    postgres@DAVID-PC:/mnt/d/a-curious-moon/curious_data$ psql
    psql (11.7 (Debian 11.7-0+deb10u1))
    Type "help" for help.

    postgres=# grant pg_read_server_files to david;
    GRANT ROLE
    postgres=# \q
    postgres@DAVID-PC:/mnt/d/a-curious-moon/curious_data$ exit
    ```