11
PostgreSQL worst practices Ilya Kosmodemiansky [email protected]

Lightening Talk - PostgreSQL Worst Practices

Embed Size (px)

Citation preview

Page 1: Lightening Talk - PostgreSQL Worst Practices

PostgreSQLworst practices

Ilya [email protected]

Page 2: Lightening Talk - PostgreSQL Worst Practices

Best practices are just boring

• Never follow them, try worst practices• Only those practices can really help you to screw the things upmost effectively

• PostgreSQL consultants are nice people, so try to make themhappy

Page 3: Lightening Talk - PostgreSQL Worst Practices

1. Use as many count(*) as you can

• Figure 301083021830123921 is very informative for the enduser

• If it changes in a second to 30108302894839434020, it is stillinformative

• select count(*) from sometable is a quite light query• Tuple estimation from pg_catalog can never be preciseenough for you

Page 4: Lightening Talk - PostgreSQL Worst Practices

2. Try to create as many indexes as you can

• Indexes consume no disk space• Indexes consume no shared_bufers• There is no overhead on DML if one and every column in atable covered with bunch of indexes

• Optimizer will definitely choose your index once you created it• Keep calm and create more indexes

Page 5: Lightening Talk - PostgreSQL Worst Practices

3. Turn autovacuum off

• It is quite auxiliary process, you can easily stop it• There is no problem at all to have 100Gb data in a databasewhich is 1Tb in size

• 2-3Tb RAM servers are cheap, IO is a fastest thing in moderncomputing

• Besides of that, everyone likes BigData

Page 6: Lightening Talk - PostgreSQL Worst Practices

4. Reinvent Slony

• If you need some data replication to another database, try toimplement it from scratch

• That allows you to run into all problems, PostgreSQL havehad since introducing Slony

Page 7: Lightening Talk - PostgreSQL Worst Practices

5. Move joins to your application

• Just select * a couple of tables into the application written inyour favorite programming language

• Than join them at the application level• Now you only need to implement nested loop join, hash joinand merge join as well as query optimizer and page cache

Page 8: Lightening Talk - PostgreSQL Worst Practices

6. Never use graphical monitoring

• You do not need graphs• Because it is an easy task to guess what was happenedyesterday at 2 a.m. using command line and grep only

Page 9: Lightening Talk - PostgreSQL Worst Practices

7. Never use Foreign Keys

• Consistency control at application level always works asexpected

• You will never get data inconsistency without constraints

Page 10: Lightening Talk - PostgreSQL Worst Practices

8. Always use text type for all columns

• It is always fun to reimplement date or ip validation in yourcode

• You will never mistaken converting ”12-31-2015 03:01AM” to”15:01 12 of undef 2015” using textfields

Page 11: Lightening Talk - PostgreSQL Worst Practices

Questions?

[email protected]