PostgreSQL: Defining a primary key on a large database

前端 未结 6 2087
面向向阳花
面向向阳花 2021-01-02 03:29

I am planing a database to store lots of text. (blog posts, news articles, etc.) The database needs to have the title, content (50k characters max), date, link and language

6条回答
  •  孤城傲影
    2021-01-02 03:47

    Some suggestions:

    • The disk storage of a 64 bit primary-key integer is negligible no matter how much content you have.
    • You'll never collide SHA256, and using it as a unique id isn't a bad idea.

    One nice thing about the hash method is that you don't have a single sequence source to generate new primary keys. This can be useful if your database needs to be segmented in some manner (say geographical distribution) for future scaling, as you don't have to worry about collisions, or a single-point-of-failure that generates sequences.

    From a coding perspective, having a single primary key can be vital for joining on extra tables of data you may add in the future. I highly recommend you use one. There are benefits to either of your proposed approaches, but the hash method might be the preferred one, just because autoincrement/sequence values can cause scalability issues sometimes.

提交回复
热议问题