> sudo apt install postgresql-10 Success. You can now start the database server using: /usr/lib/postgresql/10/bin/pg_ctl -D /var/lib/postgresql/10/main -l logfile start Ver Cluster Port Status Owner Data directory Log file 10 main 5432 down postgres /var/lib/postgresql/10/main /var/log/postgresql/postgresql-10-main.log update-alternatives: using /usr/share/postgresql/10/man/man1/postmaster.1.gz to provide /usr/share/man/man1/postmaster.1.gz (postmaster.1.gz) in auto mode Processing triggers for ureadahead (0.100.0-20) ... Processing triggers for systemd (237-3ubuntu10) ... > sudo -u postgres psql postgres psql (10.3 (Ubuntu 10.3-1)) Type "help" for help. postgres=# \password postgres Enter new password: 1 Enter it again: 1 postgres=# create DATABASE test; > sudo -u postgres psql test test=# show config_file; config_file ----------------------------------------- /etc/postgresql/10/main/postgresql.conf (1 row)
The auto_explain module provides the ability to automatically log plans for the execution of slow statements, which eliminates the need to manually execute EXPLAIN . This is especially useful for detecting non-optimized queries in large applications.Those. in Postgres it is possible to find out the request plan at the time of its execution
load 'auto_explain'; SET auto_explain.log_min_duration = 10; SET auto_explain.log_analyze = true; select count(*) from somet where number < 1000
This is useful if you need to profile a specific query. test=# SELECT pg_reload_conf(); pg_reload_conf ---------------- t (1 row)
CREATE EXTENSION IF NOT EXISTS "uuid-ossp"; create table somet( id uuid PRIMARY key, number INTEGER, text text ); insert into somet select uuid_generate_v1(), round(random() * 1000000), round(random() * 1000000)::text from generate_series(1,10000000)
select count(*) from somet where number < 1000
create index on somet (number) where number < 1000
> sudo apt install pgbadger
> pgbadger -j 4 -p '%t [%p]:[%l-1]' /var/log/postgresql/postgresql-9.6-main.log -o bad.html [========================>] Parsed 43578 bytes of 43578 (100.00%), queries: 115, events: 1 LOG: Ok, generating html report...
Source: https://habr.com/ru/post/354948/
All Articles