How would I implement separate databases for reading and writing operations?

I’m not a specialist but the read/write master database and read-only slaves pattern is a “common” pattern, especially for big applications doing mostly read accesses or data warehouses: it allows to scale (you add more read-only slaves if required) it allows to tune the databases differently (for either efficient reads or efficient writes) What would … Read more

Optimal data architecture for tagging, clouds, and searching (like StackOverflow)?

Wow I just wrote a big post and SO choked and hung on it, and when I hit my back button to resubmit, the markup editor was empty. aaargh. So here I go again… Regarding Stack Overflow, it turns out that they use SQL server 2005 full text search. Regarding the OS projects recommended by … Read more

How to create sequence if not exists

Postgres 9.5 or later IF NOT EXISTS was added to CREATE SEQUENCE in Postgres 9.5. That’s the simple solution now: CREATE SEQUENCE IF NOT EXISTS myschema.myseq; But consider details of the outdated answer anyway … And you know about serial or IDENTITY columns, right? Auto increment table column Postgres 9.4 or older Sequences share the … Read more

How to constrain a table to contain a single row?

You make sure one of the columns can only contain one value, and then make that the primary key (or apply a uniqueness constraint). CREATE TABLE T1( Lock char(1) not null, /* Other columns */, constraint PK_T1 PRIMARY KEY (Lock), constraint CK_T1_Locked CHECK (Lock=’X’) ) I have a number of these tables in various databases, … Read more