From: Marko Kreen <markokr@gmail.com>
To: Postgres Bugs List <pgsql-bugs@postgresql.org>
Subject: [9.4] SELECT repeatedly rewrites a table
Date: Fri, 17 Jul 2015 14:22:59 +0300
Message-ID: <20150717112259.GA21878@gmail.com> (raw)
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>
We recently upgraded 9.3 to 9.4 in live environment and one batch-job
query floods system with write requests. Query itself is basically
seq-scan on insert-only table.
DB: Postgres 9.4.4
OS: Ubuntu 12.04, 64-bit
HW: AWS EC2, EBS, 16G RAM
Story:
1) New VM is created, fresh initdb
2) Data is replicated in, with COPY (Londiste), indexes are created.
3) ANALYZE
4) Let machine run under normal load couple hours. It is not reproducible
immediately on fresh VM.
5) Run query (with DECLARE data_maint_cur NO SCROLL CURSOR WITH HOLD FOR).
The table has seen only inserts thus far. Here is EXPLAIN of normal run:
chatdb=# explain analyze select account_id, max(event_nr) as first_event_nr from account.event where store_time < now() - '1 month'::interval group by 1;
QUERY PLAN
-----------------------------------------------------------------------------------------------------------------------------
HashAggregate (cost=843632.92..843634.31 rows=139 width=24) (actual time=11938.390..12201.234 rows=285135 loops=1)
Group Key: account_id
-> Seq Scan on event (cost=0.00..837636.04 rows=1199378 width=24) (actual time=166.772..10883.828 rows=1049812 loops=1)
Filter: (store_time < (now() - '1 mon'::interval))
Rows Removed by Filter: 24698500
Planning time: 1.194 ms
Execution time: 12406.133 ms
6) So good run is 12s, bad run is ~1h with huge write load. The table is ~3G,
but Postgres seems to repeatedly rewrite those files.
7) It seems when I cancel bad run and VACUUM the table, it will proceed normally.
Attached is strace during bad run and backtrace.
fds for strace:
lrwx------ 1 postgres postgres 64 Jul 16 04:01 17 -> /var/lib/postgresql/9.4/main/base/16385/19297
lrwx------ 1 postgres postgres 64 Jul 16 04:01 18 -> /var/lib/postgresql/9.4/main/base/16385/19297.1
lrwx------ 1 postgres postgres 64 Jul 16 04:01 19 -> /var/lib/postgresql/9.4/main/base/16385/19297.2
--
marko
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugsAttachments:
strace.txt.gz (application/octet-stream, 2.3K) download
backtrace.txt.gz (application/octet-stream, 2.7K) downloadpostgresql.conf (text/plain, 1.8K) download
data_directory = '/var/lib/postgresql/9.4/main' # use data in another directory
hba_file = '/etc/postgresql/9.4/main/pg_hba.conf' # host-based authentication file
ident_file = '/etc/postgresql/9.4/main/pg_ident.conf' # ident configuration file
listen_addresses = '*' # what IP address(es) to listen on;
port = 5432 # (change requires restart)
max_connections = 250 # (change requires restart)
ssl = on
ssl_ciphers = 'EECDH+AES128:EDH+AES128:!aNULL'
ssl_renegotiation_limit = 0
tcp_keepalives_idle = 240
tcp_keepalives_count = 4
tcp_keepalives_interval = 15
shared_buffers = 256MB # min 128kB
maintenance_work_mem = 512MB
work_mem = 2MB
shared_preload_libraries = 'pg_logforward'
bgwriter_lru_maxpages = 200
wal_level = hot_standby
checkpoint_segments = 15
archive_mode = on
archive_command = '/bin/true'
max_wal_senders = 2
wal_keep_segments = 20 # 300M
random_page_cost = 2.0
effective_cache_size = 4GB # real default is 4GB, not 128MB...
log_rotation_age = 1d # Automatic rotation of logfiles will
log_rotation_size = 100MB
log_min_duration_statement = -1
log_checkpoints = on
log_line_prefix = '%m %r %p %d %u '
log_lock_waits = on # log lock waits >= deadlock_timeout
log_temp_files = 0 # log temporary files equal or larger
track_io_timing = on
track_functions = pl
log_autovacuum_min_duration = 15s
search_path = 'public'
datestyle = 'iso, dmy'
lc_messages = 'en_US.UTF-8' # locale for system error message
lc_monetary = 'en_US.UTF-8' # locale for monetary formatting
lc_numeric = 'en_US.UTF-8' # locale for number formatting
lc_time = 'en_US.UTF-8' # locale for time formatting
default_text_search_config = 'pg_catalog.english'
logforward.target_names = 'logproxy'
logforward.logproxy_host = '127.0.0.1'
logforward.logproxy_port = 17090
logforward.logproxy_min_elevel = 19
logforward.logproxy_format = 'json'
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-bugs@postgresql.org
Cc: markokr@gmail.com
Subject: Re: [9.4] SELECT repeatedly rewrites a table
In-Reply-To: <20150717112259.GA21878@gmail.com>
References: <20150717112259.GA21878@gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox