Skip to content
This documentation is for the end of life version of Percona Distribution for PostgreSQL 11.
Learn more about PostgreSQL 11 end of life implications. See the current documentation.
logo
Percona Product Documentation
Run in Docker
Initializing search
    percona/postgresql-docs
    percona/postgresql-docs
    • Home
      • Release notes index
      • Percona Distribution for PostgreSQL 11.22 Update (2024-01-22)
      • Percona Distribution for PostgreSQL 11.22 (2023-12-13)
      • Percona Distribution for PostgreSQL 11.21 (2023-08-31)
      • Percona Distribution for PostgreSQL 11.20 (2023-06-30)
      • Percona Distribution for PostgreSQL 11.19 Update (2023-05-22)
      • Percona Distribution for PostgreSQL 11.19 (2023-03-31)
      • Percona Distribution for PostgreSQL 11.18 (2022-12-08)
      • Percona Distribution for PostgreSQL 11.17 (2022-09-08)
      • Percona Distribution for PostgreSQL 11.16 (2022-06-07)
      • Percona Distribution for PostgreSQL 11.15 Second Update (2022-05-05)
      • Percona Distribution for PostgreSQL 11.15 Update (2022-04-14)
      • Percona Distribution for PostgreSQL 11.15 (2022-04-08)
      • Percona Distribution for PostgreSQL 11.14 (2021-12-20)
      • Percona Distribution for PostgreSQL 11.13 Update (2021-12-07)
      • Percona Distribution for PostgreSQL 11.13 (2021-09-09)
      • Percona Distribution for PostgreSQL 11.12 Third Update (2021-07-15)
      • Percona Distribution for PostgreSQL 11.12 Second Update (2021-07-01)
      • Percona Distribution for PostgreSQL 11.12 Update (2021-06-10)
      • Percona Distribution for PostgreSQL 11.12 (2021-05-24)
      • Percona Distribution for PostgreSQL 11.11 Third Update (2021-06-10)
      • Percona Distribution for PostgreSQL 11.11 Second Update (2021-05-10)
      • Percona Distribution for PostgreSQL 11.11 Update (2021-04-12)
      • Percona Distribution for PostgreSQL 11.11 (2021-03-08)
      • Percona Distribution for PostgreSQL 11.10 Update (2021-06-10)
      • Percona Distribution for PostgreSQL 11.10 (2020-12-15)
      • Percona Distribution for PostgreSQL 11.9 (2020-09-08)
      • Percona Distribution for PostgreSQL 11.8 (2020-06-11)
      • Percona Distribution for PostgreSQL 11.7 (2020-04-09)
      • Percona Distribution for PostgreSQL 11.6 (2020-01-23)
      • Percona Distribution for PostgreSQL 11 (2019-09-17)
      • Percona Distribution for PostgreSQL 11 (Beta) (2019-05-15)
        • Overview
        • Via apt
        • Via yum
        • Enable Percona Distribution for PostgreSQL extensions
        • Repositories overview
      • Run in Docker
        • Start the container
        • Connect to Percona Distribution for PostgreSQL from an application in another Docker container
        • Connect to Percona Distribution for PostgreSQL from the psql command line client
        • Enable pg_stat_monitor
      • Migrate from PostgreSQL to Percona Distribution for PostgreSQL
      • Minor Upgrade of Percona Distribution for PostgreSQL
      • pg_stat_monitor
      • High availability
        • Deploying on Debian or Ubuntu
        • Deploying on RHEL or CentOS
        • Testing the Patroni PostgreSQL Cluster
        • pgBackRest setup
      • Backup and disaster recovery
        • Deploying backup and disaster recovery solution in Percona Distribution for PostgreSQL
        • Overview
        • Deployment
        • Query spatial data
        • Upgrade spatial database
      • LDAP authentication
    • Telemetry
    • Uninstall
    • Licensing
    • Trademark policy

    • Start the container
    • Connect to Percona Distribution for PostgreSQL from an application in another Docker container
    • Connect to Percona Distribution for PostgreSQL from the psql command line client
    • Enable pg_stat_monitor

    Run Percona Distribution for PostgreSQL in a Docker container¶

    Docker images of Percona Distribution for PostgreSQL are hosted publicly on Docker Hub.

    For more information about using Docker, see the Docker Docs.

    Make sure that you are using the latest version of Docker. The ones provided via apt and yum may be outdated and cause errors.

    By default, Docker pulls the image from Docker Hub if it is not available locally.

    Docker image contents

    The Docker image of Percona Distribution for PostgreSQL includes the following components:

    Component name Description
    percona-postgresql11 A metapackage that installs the latest version of PostgreSQL
    percona-postgresql11-server The PostgreSQL server package.
    percona-postgresql-common PostgreSQL database-cluster manager. It provides a structure under which multiple versions of PostgreSQL may be installed and/or multiple clusters maintained at one time.
    percona-postgresql-client-common The manager for multiple PostgreSQL client versions.
    percona-postgresql11-contrib A collection of additional PostgreSQLcontrib extensions
    percona-postgresql11-libs Libraries for use with PostgreSQL.
    percona-pg-stat-monitor11 A Query Performance Monitoring tool for PostgreSQL.
    percona-pgaudit11 Provides detailed session or object audit logging via the standard PostgreSQL logging facility.
    percona-pgaudit11_set_user An additional layer of logging and control when unprivileged users must escalate themselves to superuser or object owner roles in order to perform needed maintenance tasks.
    percona-pg_repack11 rebuilds PostgreSQL database objects.
    percona-wal2json11 a PostgreSQL logical decoding JSON output plugin.

    Start the container¶

    1. Start a Percona Distribution for PostgreSQL container as follows:

      $ docker run --name container-name -e POSTGRES_PASSWORD=secret -d percona/percona-distribution-postgresql:tag
      

      Where:

      • container-name is the name you assign to your container
      • POSTGRES_PASSWORD is the superuser password
      • tag is the tag specifying the version you want.

      Check the full list of tags.

      Tip

      You can secure the password by exporting it to the environment file and using that to start the container.

      1. Export the password to the environment file:

        $ echo "POSTGRES_PASSWORD=secret" > .my-pg.env
        
      2. Start the container:

        $ docker run --name container-name --env-file ./.my-pg.env -d percona/percona-distribution-postgresql:tag
        
    2. Connect to the container’s interactive terminal:

      $ docker exec -it container-name bash
      

      The container-name is the name of the container that you started in the previous step.

    Connect to Percona Distribution for PostgreSQL from an application in another Docker container¶

    This image exposes the standard PostgreSQL port (5432), so container linking makes the instance available to other containers. Start other containers like this in order to link it to the Percona Distribution for PostgreSQL container:

    $ docker run --name app-container-name --network container:container-name -d app-that-uses-postgresql 
    

    where:

    • app-container-name is the name of the container where your application is running,
    • container name is the name of your Percona Distribution for PostgreSQL container, and
    • app-that-uses-postgresql is the name of your PostgreSQL client.

    Connect to Percona Distribution for PostgreSQL from the psql command line client¶

    The following command starts another container instance and runs the psql command line client against your original container, allowing you to execute SQL statements against your database:

    $ docker run -it --network container:db-container-name --name container-name percona/percona-distribution-postgresql:tag psql -h address -U postgres
    

    Where:

    • db-container-name is the name of your database container
    • container-name is the name of your container that you will use to connect to the database container using the psql command line client
    • tag is the tag specifying the Docker image version you want to use.
    • address is the network address where your database container is running. Use 127.0.0.1, if the database container is running on the local machine/host.

    Enable pg_stat_monitor¶

    To enable the pg_stat_monitor extension after launching the container, do the following:

    • connect to the server,
    • select the desired database and enable the pg_stat_monitor view for that database:
    create extension pg_stat_monitor;
    
    • to ensure that everything is set up correctly, run:
    \d pg_stat_monitor;
    
    Output
                             View "public.pg_stat_monitor"
          Column        |           Type           | Collation | Nullable | Default
    ---------------------+--------------------------+-----------+----------+---------
    bucket              | integer                  |           |          |
    bucket_start_time   | timestamp with time zone |           |          |
    userid              | oid                      |           |          |
    dbid                | oid                      |           |          |
    queryid             | text                     |           |          |
    query               | text                     |           |          |
    plan_calls          | bigint                   |           |          |
    plan_total_time     | numeric                  |           |          |
    plan_min_timei      | numeric                  |           |          |
    plan_max_time       | numeric                  |           |          |
    plan_mean_time      | numeric                  |           |          |
    plan_stddev_time    | numeric                  |           |          |
    plan_rows           | bigint                   |           |          |
    calls               | bigint                   |           |          |
    total_time          | numeric                  |           |          |
    min_time            | numeric                  |           |          |
    max_time            | numeric                  |           |          |
    mean_time           | numeric                  |           |          |
    stddev_time         | numeric                  |           |          |
    rows                | bigint                   |           |          |
    shared_blks_hit     | bigint                   |           |          |
    shared_blks_read    | bigint                   |           |          |
    shared_blks_dirtied | bigint                   |           |          |
    shared_blks_written | bigint                   |           |          |
    local_blks_hit      | bigint                   |           |          |
    local_blks_read     | bigint                   |           |          |
    local_blks_dirtied  | bigint                   |           |          |
    local_blks_written  | bigint                   |           |          |
    temp_blks_read      | bigint                   |           |          |
    temp_blks_written   | bigint                   |           |          |
    blk_read_time       | double precision         |           |          |
    blk_write_time      | double precision         |           |          |
    host                | bigint                   |           |          |
    client_ip           | inet                     |           |          |
    resp_calls          | text[]                   |           |          |
    cpu_user_time       | double precision         |           |          |
    cpu_sys_time        | double precision         |           |          |
    tables_names        | text[]                   |           |          |
    wait_event          | text                     |           |          |
    wait_event_type     | text                     |           |          |
    

    Note that the pg_stat_monitor view is available only for the databases where you enabled it. If you create a new database, make sure to create the view for it to see its statistics data.

    Contact Us

    For free technical help, visit the Percona Community Forum.

    To report bugs or submit feature requests, open a JIRA ticket.

    For paid support and managed or consulting services , contact Percona Sales.

    December 13, 2023 December 13, 2023
    Percona LLC and/or its affiliates, © 2024 — Cookie Preferences
    Made with Material for MkDocs