Increase PostgreSQL write speed at the cost of likely data loss?

前端 未结 8 1055
执笔经年
执笔经年 2021-01-29 19:08

I love that PostgreSQL is crash resistant, as I don\'t want to spend time fixing a database. However, I\'m sure there must be some things I can disable/modify so that i

8条回答
  •  一整个雨季
    2021-01-29 19:30

    Well one thing you could do to speed things up is drop the index you are creating manually - the primary key constraint already auto-creates a unique index on that column as you can see below (I'm testing on 8.3):

    postgres=> CREATE TABLE "user"
    postgres-> (
    postgres(>   id serial NOT NULL,
    postgres(>   username character varying(40),
    postgres(>   email character varying(70),
    postgres(>   website character varying(100),
    postgres(>   created integer,
    postgres(>   CONSTRAINT user_pkey PRIMARY KEY (id)
    postgres(> )
    postgres-> WITH ( OIDS=FALSE );
    NOTICE:  CREATE TABLE will create implicit sequence "user_id_seq" for serial column "user.id"
    NOTICE:  CREATE TABLE / PRIMARY KEY will create implicit index "user_pkey" for table "user"
    CREATE TABLE
    postgres=> CREATE INDEX id ON "user" USING btree (id);
    CREATE INDEX
    postgres=> \d user
                                      Table "stack.user"
      Column  |          Type          |                     Modifiers
    ----------+------------------------+---------------------------------------------------
     id       | integer                | not null default nextval('user_id_seq'::regclass)
     username | character varying(40)  |
     email    | character varying(70)  |
     website  | character varying(100) |
     created  | integer                |
    Indexes:
        "user_pkey" PRIMARY KEY, btree (id)
        "id" btree (id)
    

    Also, consider changing wal_sync_method to an option that uses O_DIRECT - this is not the default on Linux

提交回复
热议问题