User Tools

Site Tools


soft:postgresql

PostgreSQL

Configuration

listen_addresses = '*'
shared_buffers = 1024MB  # ~25% of RAM and maximum at 16G
work_mem = 16MB
maintenance_work_mem = 128MB
synchronous_commit = off # read documentation before using this
random_page_cost = 3.0  # if using ssd
track_functions = all
track_io_timing = on
shared_preload_libraries = 'pg_stat_statements'
pg_stat_statements.track = all
log_min_duration_statement = 1s
log_checkpoints = on
log_lock_waits = on
log_statement = 'ddl'
log_temp_files = 1024
log_autovacuum_min_duration = 1000
log_line_prefix = '%t [%p]: [%l-1] user=%u,db=%d '
effective_cache_size = 3072MB # 75% of ram

SQL to view size of each table and indexes

SELECT
        name,
        tuples,
        pg_size_pretty(table_size) AS table_size,
        pg_size_pretty(index_size) AS index_size,
        pg_size_pretty(toast_size) AS toast_size,
        pg_size_pretty(total_size) AS total_size
FROM (
        SELECT
                c.relname AS name,
                (c.reltuples)::BIGINT AS tuples,
                pg_relation_size((c.oid)::regclass) AS table_size,
                ((pg_total_relation_size((c.oid)::regclass) - pg_relation_size((c.oid)::regclass)) -
                CASE
                        WHEN (c.reltoastrelid <> (0)::oid) THEN pg_relation_size((c.reltoastrelid)::regclass)
                        ELSE (0)::BIGINT
                END) AS index_size,
                CASE
                        WHEN (c.reltoastrelid <> (0)::oid) THEN pg_relation_size((c.reltoastrelid)::regclass)
                        ELSE (0)::BIGINT
                END AS toast_size,
                pg_total_relation_size((c.oid)::regclass) AS total_size
        FROM 
                ((pg_class c JOIN pg_roles r ON ((r.oid = c.relowner)))
                LEFT JOIN pg_namespace n ON ((n.oid = c.relnamespace)))
        WHERE
                (((c.relkind = 'r'::"char") AND (n.nspname <> ALL (ARRAY['pg_catalog'::name, 'pg_toast'::name]))) AND pg_table_is_visible(c.oid))
        ORDER BY pg_total_relation_size((c.oid)::regclass) DESC
) AS sub;
soft/postgresql.txt · Last modified: 2019/07/24 21:17 by phil