7

PostgreSQL table names are limited to 63 chars.

Is there a performance gain to be had if I limit my table names to something like 5 chars or can I use the full 63 chars without consequence?

I understand it will be longer to type long names when creating queries, but that's what aliases are for.

2
  • 1
    No, I doubt there is difference in performance. No reason to limit to 5 characters and seriously, will you ever need 63 characters for a name? Commented Mar 20, 2014 at 20:44
  • @hypercube : well right now in my conceptual model I have a 20+ char name, something like 'customer_pays_for_user'. I was wondering if I should start to shorten the long names or just go with it.
    – jmn
    Commented Mar 21, 2014 at 19:24

1 Answer 1

10

Table names have to be stored just like any other data (in the system catalog pg_class to be precise), and there are multiple objects that are typically named matching the table name (constraints, indexes, sequences, ...) so there is a marginal cost for longer strings. But you will not be able to notice any difference in performance. Internal references are implemented with oid numbers (object identifier types), so independent of the string used as name.

The more important consideration is that your code becomes longer and harder to read and type. Typos more likely. Aliases are nice, but you still have to spell out the name in many places. So the rule of thumb should be:

  • As short as possible.
  • As long as necessary to be clear.
2
  • 'But you will not be able to notice any difference in performance.' does this hold true if I have several thousand users accessing the database ?
    – jmn
    Commented Mar 21, 2014 at 19:26
  • @jmn: Yes. The performance penalty is just too marginal. Commented Mar 21, 2014 at 19:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.