数据库列中 a 实际占用的大小取决于我的字符串大小或我的列最大大小?

The size physically occuped by a in the database column depend on my string size or on my column max size?

例如,我有一列 varchar(2000) 用于消息。 如果我的大部分消息的长度都是 50 个字符,那么占用的“内存中的实际位置”是否优化? 还是每个占2000个字符?

我使用 PostgreSQL

所需的存储(和内存)space 仅取决于列中存储的实际数据。定义为 varchar(2000) 的列最多只包含 50 个字符,不需要比定义为 varchar(50)

的列更多的存储空间或内存

Quote from the manual

If the string to be stored is shorter than the declared length, [...] values of type character varying will simply store the shorter string

(强调我的)

请注意,这对于 character 数据类型是不同的 - 但无论如何 shouldn't be used