Re: [PERFORM] Postgres becoming slow, only full vacuum fixes it
I am posting back to let you know that the DB is working fine since the changes in the autovacuum settings. I am including the changes I made for later reference to anyone that may face similar issues. Thank you all for your time and help ! On Sep 28, 2012, at 9:52, Kiriakos Tsourapas wrote: Dear all, Just letting you know that making the autovacuum policy more aggressive seems to have fixed the problem. It's been 4 days now and everything is running smoothly. Just a reminder, what I changed was : autovacuum_vacuum_scale_factor = 0.01 autovacuum_analyze_scale_factor = 0.005 making autovacuum run at 1% instead of 20% (the dafault) and the analyze run at 0,5% instead of 10%. Maybe it's more aggressive than needed... I will monitor and post back. Thank you all for your help. -- Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance
Re: [PERFORM] Postgres becoming slow, only full vacuum fixes it
-Original Message- From: Thomas Kellerer [mailto:spam_ea...@gmx.net] Sent: Tuesday, September 25, 2012 7:24 AM To: pgsql-performance@postgresql.org Subject: Re: Postgres becoming slow, only full vacuum fixes it Kiriakos Tsourapas, 25.09.2012 13:01: Thank you, I will take this into consideration, since upgrading to 9 will be much harder I assume... I think an upgrade from 8.3 to 8.4 was harder due to the removal of a lot of implicit type casts. 8.4 to 9.x shouldn't be that problematic after all (but will take longer due to the required dump/reload) Actually, 8.3 to 8.4 required db dump/restore. When upgrading from 8.4 to 9.x pg_upgrade could be used without dump/restore. Regards, Igor Neyman -- Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance
Re: [PERFORM] Postgres becoming slow, only full vacuum fixes it
On Tue, Sep 25, 2012 at 5:24 AM, Thomas Kellerer spam_ea...@gmx.net wrote: I think an upgrade from 8.3 to 8.4 was harder due to the removal of a lot of implicit type casts. FYI that was from 8.2 to 8.3 that implicit casts were removed. -- Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance
Re: [PERFORM] Postgres becoming slow, only full vacuum fixes it
Dear all, Just letting you know that making the autovacuum policy more aggressive seems to have fixed the problem. It's been 4 days now and everything is running smoothly. Just a reminder, what I changed was : autovacuum_vacuum_scale_factor = 0.01 autovacuum_analyze_scale_factor = 0.005 making autovacuum run at 1% instead of 20% (the dafault) and the analyze run at 0,5% instead of 10%. Maybe it's more aggressive than needed... I will monitor and post back. Thank you all for your help. -- Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance
Re: [PERFORM] Postgres becoming slow, only full vacuum fixes it
Kiriakos Tsourapas, 25.09.2012 13:01: Thank you, I will take this into consideration, since upgrading to 9 will be much harder I assume... I think an upgrade from 8.3 to 8.4 was harder due to the removal of a lot of implicit type casts. 8.4 to 9.x shouldn't be that problematic after all (but will take longer due to the required dump/reload) -- Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance
Re: [PERFORM] Postgres becoming slow, only full vacuum fixes it
Dear all, I am taking your suggestions one step at a time. I changed my configuration to a much more aggressive autovacuum policy (0.5% for analyzing and 1% for autovacuum). autovacuum_naptime = 1min autovacuum_vacuum_threshold = 50 #autovacuum_analyze_threshold = 50 autovacuum_vacuum_scale_factor = 0.01 autovacuum_analyze_scale_factor = 0.005 I had tables with 180.000 record and another with 2M records, so the default values of 0.2 for autovacuum would mean that 18.000 and 200K records would have to change respectively, delaying the vacuum for many days. I will monitor for the next 2-3 days and post back the results. Thank you all for your suggestions so far. Kiriakos -- Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance
Re: [PERFORM] Postgres becoming slow, only full vacuum fixes it
[resending because I accidentally failed to include the list] Kiriakos Tsourapas wrote: I am taking your suggestions one step at a time. I changed my configuration to a much more aggressive autovacuum policy (0.5% for analyzing and 1% for autovacuum). autovacuum_naptime = 1min autovacuum_vacuum_threshold = 50 #autovacuum_analyze_threshold = 50 autovacuum_vacuum_scale_factor = 0.01 autovacuum_analyze_scale_factor = 0.005 I had tables with 180.000 record and another with 2M records, so the default values of 0.2 for autovacuum would mean that 18.000 and 200K records would have to change respectively, delaying the vacuum for many days. I am concerned that your initial email said that you had this setting: autovacuum_naptime = 28800 This is much too high for most purposes; small, frequently-modified tables won't be kept in good shape with this setting. Perhaps you're not having that problem at the moment, but it's risky to assume that you don't and never will. When autovacuum wakes up and there is nothing to do it should go back to sleep very quickly. Don't expect too much from just making autovacuum run more often until you have eliminated existing bloat (autovacuum generally just limits further growth of bloat) and updated to the latest 8.4 minor release. The following bugs fixes are among many you are living without until you upgrade: - Prevent show_session_authorization() from crashing within autovacuum processes (Tom Lane) - Fix persistent slowdown of autovacuum workers when multiple workers remain active for a long time (Tom Lane) The effective vacuum_cost_limit for an autovacuum worker could drop to nearly zero if it processed enough tables, causing it to run extremely slowly. - Fix VACUUM so that it always updates pg_class.reltuples/relpages (Tom Lane) This fixes some scenarios where autovacuum could make increasingly poor decisions about when to vacuum tables. - Fix btree index corruption from insertions concurrent with vacuuming (Tom Lane) An index page split caused by an insertion could sometimes cause a concurrently-running VACUUM to miss removing index entries that it should remove. After the corresponding table rows are removed, the dangling index entries would cause errors (such as could not read block N in file ...) or worse, silently wrong query results after unrelated rows are re-inserted at the now-free table locations. This bug has been present since release 8.2, but occurs so infrequently that it was not diagnosed until now. If you have reason to suspect that it has happened in your database, reindexing the affected index will fix things. - Ensure autovacuum worker processes perform stack depth checking properly (Heikki Linnakangas) Previously, infinite recursion in a function invoked by auto-ANALYZE could crash worker processes. - Only allow autovacuum to be auto-canceled by a directly blocked process (Tom Lane) The original coding could allow inconsistent behavior in some cases; in particular, an autovacuum could get canceled after less than deadlock_timeout grace period. - Improve logging of autovacuum cancels (Robert Haas) -Kevin -- Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance
Re: [PERFORM] Postgres becoming slow, only full vacuum fixes it
Hi Kevin, On Sep 26, 2012, at 14:39, Kevin Grittner wrote: I am concerned that your initial email said that you had this setting: autovacuum_naptime = 28800 This is much too high for most purposes; small, frequently-modified tables won't be kept in good shape with this setting. Perhaps you're not having that problem at the moment, but it's risky to assume that you don't and never will. When autovacuum wakes up and there is nothing to do it should go back to sleep very quickly. I used the 28800 (8hours) setting after I realized that the default 1min was not helping. I also changed other parameters when I changed it to 8 hours, to make sure tables would be auto vacuumed. The problem with my setting was that autovacuum gets stopped if a lock is needed on the table. So, it was very bad choice to run it every 8 hours, because usually it got stopped and never did anything. So, I turned back to the original setting of 1min but changed the autovacuum_vacuum_scale_factor to 1% instead of 20%. Hopefully tables will be more frequently vacuumed now and the problem will not appear again. Don't expect too much from just making autovacuum run more often until you have eliminated existing bloat (autovacuum generally just limits further growth of bloat) and updated to the latest 8.4 minor release. The following bugs fixes are among many you are living without until you upgrade: Can you please suggest of a way to - find if there is existing bloat - eliminate it Thank you
Re: [PERFORM] Postgres becoming slow, only full vacuum fixes it
Thank you, I will take this into consideration, since upgrading to 9 will be much harder I assume... On Sep 24, 2012, at 15:23, MirrorX wrote: i remember having a server with 8.4.4 where we had multiple problems with autovacuum. if i am not mistaken there are some bugs related with vacuum until 8.4.7. i would suggest you to upgrade to the latest 8.4.x version -- Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance
Re: [PERFORM] Postgres becoming slow, only full vacuum fixes it
Hi Mark, When the problem appears, vacuuming is not helping. I ran vacuum manually and the problem was still there. Only full vacuum worked. As far as I have understood, autovacuuming is NOT doing FULL vacuum. So, messing around with its values should not help me in any way. Thanks Given that vacuum full fixes the issue I suspect you need to have autovacuum set wake up much sooner, not later. So autovacuum_naptime = 28800 or even = 60 (i.e the default) is possibly too long. We have several database here where I change this setting to 10 i.e: autovacuum_naptime = 10s in order to avoid massive database bloat and queries that get slower and slower... You might want to be a bit *less* aggressive with autovacuum_vacuum_scale_factor - I usually have this at 0.1, i.e: autovacuum_vacuum_scale_factor = 0.1 otherwise you will be vacuuming all the time - which is usually not what you want (not for all your tables anyway). regards Mark -- Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance -- Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance
Re: [PERFORM] Postgres becoming slow, only full vacuum fixes it
Hi, Suggestion noted. Nevertheless, I cannot imagine what it would help. Actually, the cost_delay makes autovacuum freeze when it takes more time than expected, therefore, having it enabled should help the system. I may try it as a last possible resolution (remember that I have to wait for a couple of days for the problem to appear, so any test I perform will be taking days to figure out if it helped !!!) I had similar issue and I disabled cost based auto vacuum: autovacuum_vacuum_cost_delay = -1 -1 says that vacuum_cost_delay will be used and default value for vacuum_cost_delay is 0 (ie. off) Of couse you need to change other autovacuum settings but you did that. -- Ondrej Ivanic (ondrej.iva...@gmail.com) -- Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance
Re: [PERFORM] Postgres becoming slow, only full vacuum fixes it
Hi, On 25 September 2012 21:10, Kiriakos Tsourapas kts...@gmail.com wrote: Suggestion noted. Nevertheless, I cannot imagine what it would help. Actually, the cost_delay makes autovacuum freeze when it takes more time than expected, therefore, having it enabled should help the system. Yes, and I think that freeze might be part of your problem. You can: - turn of auto cost based vacuum - or properly set cost parameters: vacuum_cost_page_hit (1), vacuum_cost_page_miss (10), vacuum_cost_page_dirty (20) and vacuum_cost_limit (200) In order to freeze ie. reach vacuum_cost_limit auto vacuum needs to: - vacuum up to 200 buffers found in the shared buffer cache (200 / vacuum_cost_page_hit = 200) - or vacuum up to 20 buffers that have to be read from disk (200 / vacuum_cost_page_miss = 20) - or when vacuum modifies up to 10 blocks that were previously clean (200 / vacuum_cost_page_dirty = 10) Basically, you can fiddle with all three parameters until the cows come home or just disable cost based auto vacuum. I think your configuration can handle agressive auto vacuum. -- Ondrej Ivanic (ondrej.iva...@gmail.com) -- Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance
[PERFORM] Postgres becoming slow, only full vacuum fixes it
Hi, The problem : Postgres is becoming slow, day after day, and only a full vacuum fixes the problem. Information you may need to evaluate : The problem lies on all tables and queries, as far as I can tell, but we can focus on a single table for better comprehension. The queries I am running to test the speed are : INSERT INTO AWAITINGSTATUSSMPP VALUES('143428', '', 1, '2012-06-16 13:39:19', '111'); DELETE FROM AWAITINGSTATUSSMPP WHERE SMSCMSGID = '' AND CONNECTIONID = 1; SELECT * FROM AWAITINGSTATUSSMPP WHERE SMSCMSGID = '' AND CONNECTIONID = 1; After a full vacuum, they run in about 100ms. Today, before the full vacuum, they were taking around 500ms. Below is an explain analyze of the commands AFTER a full vacuum. I did not run it before, so I can not post relevant info before the vacuum. So, after the full vacuum : explain analyze INSERT INTO AWAITINGSTATUSSMPP VALUES('143428', '', 1, '2012-06-16 13:39:19', '111'); Result (cost=0.00..0.01 rows=1 width=0) (actual time=0.001..0.002 rows=1 loops=1) Trigger for constraint FK_AWAITINGSTATUSSMPP_MESSAGES: time=0.131 calls=1 Trigger bucardo_add_delta: time=0.454 calls=1 Trigger bucardo_triggerkick_MassSMs: time=0.032 calls=1 Total runtime: 0.818 ms explain analyze DELETE FROM AWAITINGSTATUSSMPP WHERE SMSCMSGID = '' AND CONNECTIONID = 1;Seq Scan on AWAITINGSTATUSSMPP (cost=0.00..2.29 rows=1 width=6) (actual time=0.035..0.035 rows=0 loops=1) Filter: (((SMSCMSGID)::text = ''::text) AND (CONNECTIONID = 1)) Trigger bucardo_triggerkick_MassSMs: time=0.066 calls=1 Total runtime: 0.146 ms explain analyze SELECT * FROM AWAITINGSTATUSSMPP WHERE SMSCMSGID = '' AND CONNECTIONID = 1; Seq Scan on AWAITINGSTATUSSMPP (cost=0.00..2.29 rows=1 width=557) (actual time=0.028..0.028 rows=0 loops=1) Filter: (((SMSCMSGID)::text = ''::text) AND (CONNECTIONID = 1)) Total runtime: 0.053 ms Below are the metadata of the table : = CREATE TABLE AWAITINGSTATUSSMPP ( MESSAGEID bigint NOT NULL, SMSCMSGID character varying(50) NOT NULL, CONNECTIONID smallint NOT NULL, EXPIRE_TIME timestamp without time zone NOT NULL, RECIPIENT character varying(20) NOT NULL, CLIENT_MSG_ID character varying(255), CONSTRAINT PK_AWAITINGSTATUSSMPP PRIMARY KEY (SMSCMSGID, CONNECTIONID), CONSTRAINT FK_AWAITINGSTATUSSMPP_MESSAGES FOREIGN KEY (MESSAGEID) REFERENCES MESSAGES (ID) MATCH SIMPLE ON UPDATE NO ACTION ON DELETE CASCADE ) WITH ( OIDS=FALSE ); ALTER TABLE AWAITINGSTATUSSMPP OWNER TO postgres; GRANT ALL ON TABLE AWAITINGSTATUSSMPP TO MassSMsUsers; CREATE INDEX IX_AWAITINGSTATUSSMPP_MSGID_RCP ON AWAITINGSTATUSSMPP USING btree (MESSAGEID, RECIPIENT); CREATE TRIGGER bucardo_add_delta AFTER INSERT OR UPDATE OR DELETE ON AWAITINGSTATUSSMPP FOR EACH ROW EXECUTE PROCEDURE bucardo.bucardo_add_delta_SMSCMSGID|CONNECTIONID(); CREATE TRIGGER bucardo_triggerkick_MassSMs AFTER INSERT OR UPDATE OR DELETE OR TRUNCATE ON AWAITINGSTATUSSMPP FOR EACH STATEMENT EXECUTE PROCEDURE bucardo.bucardo_triggerkick_MassSMs(); = The table only has about 200 records because it is being used a temporary storage and records are constantly inserted and deleted. BUT please don't get hold on this fact, because as I already said, the speed problem is not restricted to this table. The same problems appear on the following query UPDATE MESSAGES SET SENT = SENT + 1 WHERE ID = 143447; and MESSAGES table has mainly inserts and few deletes... My postgresql.conf file : == port = 5433 # (change requires restart) max_connections = 100 # (change requires restart) shared_buffers = 256MB # min 128kB. DoubleIP - Default was 32MB synchronous_commit = off# immediate fsync at commit. DoubleIP - Default was on effective_cache_size = 512MB# DoubleIP - Default was 128MB log_destination = 'stderr' # Valid values are combinations of logging_collector = on # Enable capturing of stderr and csvlog silent_mode = on# Run server silently. log_line_prefix = '%t %d %u ' # special values: log_autovacuum_min_duration = 0 # -1 disables, 0 logs all actions and autovacuum_naptime = 28800 # time between autovacuum runs. DoubleIP - default was 1min autovacuum_vacuum_threshold = 100 # min number of row updates before autovacuum_vacuum_scale_factor = 0.0# fraction of table size before vacuum. DoubleIP - default was 0.2 datestyle = 'iso, mdy' 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 =
Re: [PERFORM] Postgres becoming slow, only full vacuum fixes it
Sorry, forgot to mention the most obvious and important information : My postgres is 8.4.2 On Sep 24, 2012, at 13:33, Kiriakos Tsourapas wrote: Hi, The problem : Postgres is becoming slow, day after day, and only a full vacuum fixes the problem. Information you may need to evaluate : The problem lies on all tables and queries, as far as I can tell, but we can focus on a single table for better comprehension. The queries I am running to test the speed are : INSERT INTO AWAITINGSTATUSSMPP VALUES('143428', '', 1, '2012-06-16 13:39:19', '111'); DELETE FROM AWAITINGSTATUSSMPP WHERE SMSCMSGID = '' AND CONNECTIONID = 1; SELECT * FROM AWAITINGSTATUSSMPP WHERE SMSCMSGID = '' AND CONNECTIONID = 1; After a full vacuum, they run in about 100ms. Today, before the full vacuum, they were taking around 500ms. Below is an explain analyze of the commands AFTER a full vacuum. I did not run it before, so I can not post relevant info before the vacuum. So, after the full vacuum : explain analyze INSERT INTO AWAITINGSTATUSSMPP VALUES('143428', '', 1, '2012-06-16 13:39:19', '111'); Result (cost=0.00..0.01 rows=1 width=0) (actual time=0.001..0.002 rows=1 loops=1) Trigger for constraint FK_AWAITINGSTATUSSMPP_MESSAGES: time=0.131 calls=1 Trigger bucardo_add_delta: time=0.454 calls=1 Trigger bucardo_triggerkick_MassSMs: time=0.032 calls=1 Total runtime: 0.818 ms explain analyze DELETE FROM AWAITINGSTATUSSMPP WHERE SMSCMSGID = '' AND CONNECTIONID = 1;Seq Scan on AWAITINGSTATUSSMPP (cost=0.00..2.29 rows=1 width=6) (actual time=0.035..0.035 rows=0 loops=1) Filter: (((SMSCMSGID)::text = ''::text) AND (CONNECTIONID = 1)) Trigger bucardo_triggerkick_MassSMs: time=0.066 calls=1 Total runtime: 0.146 ms explain analyze SELECT * FROM AWAITINGSTATUSSMPP WHERE SMSCMSGID = '' AND CONNECTIONID = 1; Seq Scan on AWAITINGSTATUSSMPP (cost=0.00..2.29 rows=1 width=557) (actual time=0.028..0.028 rows=0 loops=1) Filter: (((SMSCMSGID)::text = ''::text) AND (CONNECTIONID = 1)) Total runtime: 0.053 ms Below are the metadata of the table : = CREATE TABLE AWAITINGSTATUSSMPP ( MESSAGEID bigint NOT NULL, SMSCMSGID character varying(50) NOT NULL, CONNECTIONID smallint NOT NULL, EXPIRE_TIME timestamp without time zone NOT NULL, RECIPIENT character varying(20) NOT NULL, CLIENT_MSG_ID character varying(255), CONSTRAINT PK_AWAITINGSTATUSSMPP PRIMARY KEY (SMSCMSGID, CONNECTIONID), CONSTRAINT FK_AWAITINGSTATUSSMPP_MESSAGES FOREIGN KEY (MESSAGEID) REFERENCES MESSAGES (ID) MATCH SIMPLE ON UPDATE NO ACTION ON DELETE CASCADE ) WITH ( OIDS=FALSE ); ALTER TABLE AWAITINGSTATUSSMPP OWNER TO postgres; GRANT ALL ON TABLE AWAITINGSTATUSSMPP TO MassSMsUsers; CREATE INDEX IX_AWAITINGSTATUSSMPP_MSGID_RCP ON AWAITINGSTATUSSMPP USING btree (MESSAGEID, RECIPIENT); CREATE TRIGGER bucardo_add_delta AFTER INSERT OR UPDATE OR DELETE ON AWAITINGSTATUSSMPP FOR EACH ROW EXECUTE PROCEDURE bucardo.bucardo_add_delta_SMSCMSGID|CONNECTIONID(); CREATE TRIGGER bucardo_triggerkick_MassSMs AFTER INSERT OR UPDATE OR DELETE OR TRUNCATE ON AWAITINGSTATUSSMPP FOR EACH STATEMENT EXECUTE PROCEDURE bucardo.bucardo_triggerkick_MassSMs(); = The table only has about 200 records because it is being used a temporary storage and records are constantly inserted and deleted. BUT please don't get hold on this fact, because as I already said, the speed problem is not restricted to this table. The same problems appear on the following query UPDATE MESSAGES SET SENT = SENT + 1 WHERE ID = 143447; and MESSAGES table has mainly inserts and few deletes... My postgresql.conf file : == port = 5433 # (change requires restart) max_connections = 100 # (change requires restart) shared_buffers = 256MB # min 128kB. DoubleIP - Default was 32MB synchronous_commit = off# immediate fsync at commit. DoubleIP - Default was on effective_cache_size = 512MB# DoubleIP - Default was 128MB log_destination = 'stderr' # Valid values are combinations of logging_collector = on # Enable capturing of stderr and csvlog silent_mode = on# Run server silently. log_line_prefix = '%t %d %u ' # special values: log_autovacuum_min_duration = 0 # -1 disables, 0 logs all actions and autovacuum_naptime = 28800 # time between autovacuum runs. DoubleIP - default was 1min autovacuum_vacuum_threshold = 100 # min number of row updates before autovacuum_vacuum_scale_factor = 0.0# fraction of table size before vacuum. DoubleIP - default was 0.2 datestyle = 'iso, mdy' lc_messages = 'en_US.UTF-8' # locale for system error
Re: [PERFORM] Postgres becoming slow, only full vacuum fixes it
Hello, 1) upgrade your PostgreSQL installation, there have been numerous bugfixes releases since 8.4.2 2) you'll have to show us an explain analyze of the slow queries. If I take a look at those you provided everything run i less than 1ms. 3) with 200 records you'll always have a seqscan 4) how much memory do you have ? shared_buffers = 256MB and effective_cache_size = 512MB looks OK only if you have between 1 and 2GB of RAM 5) synchronous_commit = off should only be used if you have a battery-backed write cache. 6) autovacuum_naptime should be changed only if autovacuum is constantly running (so if you have dozen of databases in your cluster) 7) are you sure the problem isn't related to Bucardo ? Julien On 09/24/2012 13:55, Kiriakos Tsourapas wrote: Sorry, forgot to mention the most obvious and important information : My postgres is 8.4.2 On Sep 24, 2012, at 13:33, Kiriakos Tsourapas wrote: Hi, The problem : *Postgres is becoming slow, day after day, and only a full vacuum fixes the problem*. Information you may need to evaluate : The problem lies on all tables and queries, as far as I can tell, but we can focus on a single table for better comprehension. The queries I am running to test the speed are : INSERT INTO AWAITINGSTATUSSMPP VALUES('143428', '', 1, '2012-06-16 13:39:19', '111'); DELETE FROM AWAITINGSTATUSSMPP WHERE SMSCMSGID = '' AND CONNECTIONID = 1; SELECT * FROM AWAITINGSTATUSSMPP WHERE SMSCMSGID = '' AND CONNECTIONID = 1; After a full vacuum, they run in about 100ms. Today, before the full vacuum, they were taking around 500ms. Below is an explain analyze of the commands AFTER a full vacuum. I did not run it before, so I can not post relevant info before the vacuum. So, after the full vacuum : explain analyze INSERT INTO AWAITINGSTATUSSMPP VALUES('143428', '', 1, '2012-06-16 13:39:19', '111'); Result (cost=0.00..0.01 rows=1 width=0) (actual time=0.001..0.002 rows=1 loops=1) Trigger for constraint FK_AWAITINGSTATUSSMPP_MESSAGES: time=0.131 calls=1 Trigger bucardo_add_delta: time=0.454 calls=1 Trigger bucardo_triggerkick_MassSMs: time=0.032 calls=1 Total runtime: 0.818 ms explain analyze DELETE FROM AWAITINGSTATUSSMPP WHERE SMSCMSGID = '' AND CONNECTIONID = 1;Seq Scan on AWAITINGSTATUSSMPP (cost=0.00..2.29 rows=1 width=6) (actual time=0.035..0.035 rows=0 loops=1) Filter: (((SMSCMSGID)::text = ''::text) AND (CONNECTIONID = 1)) Trigger bucardo_triggerkick_MassSMs: time=0.066 calls=1 Total runtime: 0.146 ms explain analyze SELECT * FROM AWAITINGSTATUSSMPP WHERE SMSCMSGID = '' AND CONNECTIONID = 1; Seq Scan on AWAITINGSTATUSSMPP (cost=0.00..2.29 rows=1 width=557) (actual time=0.028..0.028 rows=0 loops=1) Filter: (((SMSCMSGID)::text = ''::text) AND (CONNECTIONID = 1)) Total runtime: 0.053 ms Below are the metadata of the table : = CREATE TABLE AWAITINGSTATUSSMPP ( MESSAGEID bigint NOT NULL, SMSCMSGID character varying(50) NOT NULL, CONNECTIONID smallint NOT NULL, EXPIRE_TIME timestamp without time zone NOT NULL, RECIPIENT character varying(20) NOT NULL, CLIENT_MSG_ID character varying(255), CONSTRAINT PK_AWAITINGSTATUSSMPP PRIMARY KEY (SMSCMSGID, CONNECTIONID), CONSTRAINT FK_AWAITINGSTATUSSMPP_MESSAGES FOREIGN KEY (MESSAGEID) REFERENCES MESSAGES (ID) MATCH SIMPLE ON UPDATE NO ACTION ON DELETE CASCADE ) WITH ( OIDS=FALSE ); ALTER TABLE AWAITINGSTATUSSMPP OWNER TO postgres; GRANT ALL ON TABLE AWAITINGSTATUSSMPP TO MassSMsUsers; CREATE INDEX IX_AWAITINGSTATUSSMPP_MSGID_RCP ON AWAITINGSTATUSSMPP USING btree (MESSAGEID, RECIPIENT); CREATE TRIGGER bucardo_add_delta AFTER INSERT OR UPDATE OR DELETE ON AWAITINGSTATUSSMPP FOR EACH ROW EXECUTE PROCEDURE bucardo.bucardo_add_delta_SMSCMSGID|CONNECTIONID(); CREATE TRIGGER bucardo_triggerkick_MassSMs AFTER INSERT OR UPDATE OR DELETE OR TRUNCATE ON AWAITINGSTATUSSMPP FOR EACH STATEMENT EXECUTE PROCEDURE bucardo.bucardo_triggerkick_MassSMs(); = The table only has about 200 records because it is being used a temporary storage and records are constantly inserted and deleted. BUT please don't get hold on this fact, because as I already said, the speed problem is not restricted to this table. The same problems appear on the following query UPDATE MESSAGES SET SENT = SENT + 1 WHERE ID = 143447; and MESSAGES table has mainly inserts and few deletes... My postgresql.conf file : == port = 5433 # (change requires restart) max_connections = 100 # (change requires restart) shared_buffers = 256MB # min 128kB. DoubleIP - Default was 32MB synchronous_commit = off# immediate fsync at commit. DoubleIP - Default was on effective_cache_size = 512MB# DoubleIP - Default was 128MB log_destination = 'stderr' # Valid values are combinations
Re: [PERFORM] Postgres becoming slow, only full vacuum fixes it
On Monday, September 24, 2012 02:21:09 PM Julien Cigar wrote: 5) synchronous_commit = off should only be used if you have a battery-backed write cache. Huh? Are you possibly confusing this with full_page_writes? Greetings, Andres -- Andres Freund http://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Training Services -- Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance
Re: [PERFORM] Postgres becoming slow, only full vacuum fixes it
On 09/24/2012 14:34, Andres Freund wrote: On Monday, September 24, 2012 02:21:09 PM Julien Cigar wrote: 5) synchronous_commit = off should only be used if you have a battery-backed write cache. Huh? Are you possibly confusing this with full_page_writes? indeed...! sorry for that (note that you still have a (very) small chance of loosing data with synchronous_commit = off if your server crashes between two commit chunks) Greetings, Andres -- No trees were killed in the creation of this message. However, many electrons were terribly inconvenienced. attachment: jcigar.vcf -- Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance
Re: [PERFORM] Postgres becoming slow, only full vacuum fixes it
Hi, Thank you for your response. Please find below my answers/comments. On Sep 24, 2012, at 15:21, Julien Cigar wrote: Hello, 1) upgrade your PostgreSQL installation, there have been numerous bugfixes releases since 8.4.2 Not possible right now. It will have to be the last solution. 2) you'll have to show us an explain analyze of the slow queries. If I take a look at those you provided everything run i less than 1ms. Will do so in a couple of days that it will get slow again. 3) with 200 records you'll always have a seqscan Does it really matter? I mean, with 200 records any query should be ultra fast. Right ? 4) how much memory do you have ? shared_buffers = 256MB and effective_cache_size = 512MB looks OK only if you have between 1 and 2GB of RAM I have included the server specs and the results of top commands, showing that we have 8GB ram and how much memory is used/cached/swapped. Personally I don't quite understand the linux memory, but I have posted them hoping you may see something I don't. 5) synchronous_commit = off should only be used if you have a battery-backed write cache. I agree with the comments that have followed my post. I have changed it, knowing there is a small risk, but hoping it will help our performance. 6) autovacuum_naptime should be changed only if autovacuum is constantly running (so if you have dozen of databases in your cluster) As I said, changing the autovacuum values have not changed the problem. So, you may as well consider that we have the default values for autovacuuming... the problem existed with the default values too. 7) are you sure the problem isn't related to Bucardo ? Not at all sure... I have no idea. Can you suggest of a way to figure it out ? Thank you -- Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance
Re: [PERFORM] Postgres becoming slow, only full vacuum fixes it
On Monday, September 24, 2012 02:53:59 PM Julien Cigar wrote: On 09/24/2012 14:34, Andres Freund wrote: On Monday, September 24, 2012 02:21:09 PM Julien Cigar wrote: 5) synchronous_commit = off should only be used if you have a battery-backed write cache. Huh? Are you possibly confusing this with full_page_writes? indeed...! sorry for that (note that you still have a (very) small chance of loosing data with synchronous_commit = off if your server crashes between two commit chunks) Sure, you have a chance of loosing the last some transactions, but you won't corrupt anything. Thats the entire point of the setting ;) Greetings, Andres -- Andres Freund http://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Training Services -- Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance
Re: [PERFORM] Postgres becoming slow, only full vacuum fixes it
On 09/24/2012 15:51, Kiriakos Tsourapas wrote: Hi, Thank you for your response. Please find below my answers/comments. On Sep 24, 2012, at 15:21, Julien Cigar wrote: Hello, 1) upgrade your PostgreSQL installation, there have been numerous bugfixes releases since 8.4.2 Not possible right now. It will have to be the last solution. 2) you'll have to show us an explain analyze of the slow queries. If I take a look at those you provided everything run i less than 1ms. Will do so in a couple of days that it will get slow again. 3) with 200 records you'll always have a seqscan Does it really matter? I mean, with 200 records any query should be ultra fast. Right ? right..! 4) how much memory do you have ? shared_buffers = 256MB and effective_cache_size = 512MB looks OK only if you have between 1 and 2GB of RAM I have included the server specs and the results of top commands, showing that we have 8GB ram and how much memory is used/cached/swapped. Personally I don't quite understand the linux memory, but I have posted them hoping you may see something I don't. with 8GB of RAM I would start with shared_buffers to 1GB and effective_cache_size to 4GB. I would also change the default work_mem to 32MB and maintenance_work_mem to 512MB 5) synchronous_commit = off should only be used if you have a battery-backed write cache. I agree with the comments that have followed my post. I have changed it, knowing there is a small risk, but hoping it will help our performance. 6) autovacuum_naptime should be changed only if autovacuum is constantly running (so if you have dozen of databases in your cluster) As I said, changing the autovacuum values have not changed the problem. So, you may as well consider that we have the default values for autovacuuming... the problem existed with the default values too. 7) are you sure the problem isn't related to Bucardo ? Not at all sure... I have no idea. Can you suggest of a way to figure it out ? Unfortunately I never used Bucardo, but be sure that it's not a problem with your network (and that you understand all the challenges involved in multi-master replication) Thank you -- No trees were killed in the creation of this message. However, many electrons were terribly inconvenienced. attachment: jcigar.vcf -- Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance
Re: [PERFORM] Postgres becoming slow, only full vacuum fixes it
i remember having a server with 8.4.4 where we had multiple problems with autovacuum. if i am not mistaken there are some bugs related with vacuum until 8.4.7. i would suggest you to upgrade to the latest 8.4.x version BR, -- View this message in context: http://postgresql.1045698.n5.nabble.com/Postgres-becoming-slow-only-full-vacuum-fixes-it-tp5725119p5725129.html Sent from the PostgreSQL - performance mailing list archive at Nabble.com. -- Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance
Re: [PERFORM] Postgres becoming slow, only full vacuum fixes it
Hi, On 24 September 2012 20:33, Kiriakos Tsourapas kts...@gmail.com wrote: The problem : Postgres is becoming slow, day after day, and only a full vacuum fixes the problem. Information you may need to evaluate : The problem lies on all tables and queries, as far as I can tell, but we can focus on a single table for better comprehension. The queries I am running to test the speed are : INSERT INTO AWAITINGSTATUSSMPP VALUES('143428', '', 1, '2012-06-16 13:39:19', '111'); DELETE FROM AWAITINGSTATUSSMPP WHERE SMSCMSGID = '' AND CONNECTIONID = 1; SELECT * FROM AWAITINGSTATUSSMPP WHERE SMSCMSGID = '' AND CONNECTIONID = 1; After a full vacuum, they run in about 100ms. Today, before the full vacuum, they were taking around 500ms. I had similar issue and I disabled cost based auto vacuum: autovacuum_vacuum_cost_delay = -1 -1 says that vacuum_cost_delay will be used and default value for vacuum_cost_delay is 0 (ie. off) Of couse you need to change other autovacuum settings but you did that. -- Ondrej Ivanic (ondrej.iva...@gmail.com) -- Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance
Re: [PERFORM] Postgres becoming slow, only full vacuum fixes it
On 24/09/12 22:33, Kiriakos Tsourapas wrote: Hi, The problem : Postgres is becoming slow, day after day, and only a full vacuum fixes the problem. My postgresql.conf file : == port = 5433 # (change requires restart) max_connections = 100 # (change requires restart) shared_buffers = 256MB # min 128kB. DoubleIP - Default was 32MB synchronous_commit = off# immediate fsync at commit. DoubleIP - Default was on effective_cache_size = 512MB# DoubleIP - Default was 128MB log_destination = 'stderr' # Valid values are combinations of logging_collector = on # Enable capturing of stderr and csvlog silent_mode = on# Run server silently. log_line_prefix = '%t %d %u ' # special values: log_autovacuum_min_duration = 0 # -1 disables, 0 logs all actions and autovacuum_naptime = 28800 # time between autovacuum runs. DoubleIP - default was 1min autovacuum_vacuum_threshold = 100 # min number of row updates before autovacuum_vacuum_scale_factor = 0.0# fraction of table size before vacuum. DoubleIP - default was 0.2 datestyle = 'iso, mdy' 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' Given that vacuum full fixes the issue I suspect you need to have autovacuum set wake up much sooner, not later. So autovacuum_naptime = 28800 or even = 60 (i.e the default) is possibly too long. We have several database here where I change this setting to 10 i.e: autovacuum_naptime = 10s in order to avoid massive database bloat and queries that get slower and slower... You might want to be a bit *less* aggressive with autovacuum_vacuum_scale_factor - I usually have this at 0.1, i.e: autovacuum_vacuum_scale_factor = 0.1 otherwise you will be vacuuming all the time - which is usually not what you want (not for all your tables anyway). regards Mark -- Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance