Postgres performance issues

前端 未结 4 1600
忘了有多久
忘了有多久 2021-02-05 17:09

We are running Postgres 9.1.3 and we have recently started to run into major performance problems on one of our servers.

Our queries ran fine for a while, but as of Augu

4条回答
  •  时光说笑
    2021-02-05 17:50

    Your biggest problem is this line:

    autovacuum                | off
    

    Turning it on won't immediately cure the problem, but it should keep things from eroding further. There are almost no cases where it is a good idea to turn this off. The main exception is a big bulk load followed by an explicit VACUUM FREEZE ANALYZE, after which autovacuum should be turned back on. With autovacuum off, you will see performance degrade, just as you have. Once the database has gotten into such bad shape, it requires more aggressive maintenance than autovacuum can provide to recover.

    checkpoint_segments       | 6
    

    Increasing this will help data modifications, but won't do much to improve the speed of SELECT statements.

    fsync                     | off
    full_page_writes          | off
    

    These settings tell PostgreSQL to speed up writes at the expense of persistence. If your hardware or OS (or VM) crashes or is abruptly killed, your database will be corrupted and your best bet will be to restore from your last known good backup. (Of course, since hardware can fail at any time, if you care about losing the data, you have a good backup strategy in place.)

    maintenance_work_mem      | 1GB
    

    This is too high for an 8GB VM. You can always boost it on a single connection before running some heavy maintenance on that connection.

    wal_writer_delay          | 10ms
    

    Even seasoned experts have trouble adjusting this to something that gets better performance than the default. It is almost always best left alone.

    Your best bet at this point is to use pg_dumpall to dump your database cluster to some other medium, start with a fresh initdb, and restore. As a database superuser, run VACUUM FREEZE ANALYZE (the FREEZE is not generally recommended except after a bulk load like that), and run with autovacuum turned on.

    I highly recommend that you get a copy of Greg Smith's "PostgreSQL 9.0 High Performance" book, and read it carefully. (Full disclosure, I was one of the technical reviewers for the book, but get no money from sales.) One of the first things he recommends is getting benchmark numbers on the speed of your RAM and disk before you even install PostgreSQL -- that way you know what you're dealing with.

提交回复
热议问题