Q: DatabaseMetaData.getColumns has strange column size for int value I have a PostgreSQL table
create table test (
id int,
name varchar(2),
active boolean,
long_id bigint,
created timestamptz);
)

I want to get name, type and size of each column in this table. This is my code:
public static void main(final String[] args) throws SQLException {
        final Connection connection = DriverManager.getConnection("jdbc:postgresql://127.0.0.1:5432/test", "postgres", "123");
        final DatabaseMetaData metaData = connection.getMetaData();
        try (final ResultSet resultSet = metaData.getColumns("public", null, "test", null)) {
            while (resultSet.next()) {
                System.out.println(resultSet.getString("COLUMN_NAME") + " " + resultSet.getInt("DATA_TYPE") + " " + resultSet.getInt("COLUMN_SIZE"));
            }
        }
    }

This is the output
id 4 10
name 12 2
active -7 1
long_id -5 19
created 93 35

The third column shows column size, for example for boolean value active it's 1 byte. But why does it show 10 bytes for id value (which is int in PostgreSQL) instead of 4? 

A: As documented in DatabaseMetaData.getColumns (emphasis mine):

The COLUMN_SIZE column specifies the column size for the given column.
  For numeric data, this is the maximum precision. For character data, this is the length in characters. For datetime datatypes, this
  is the length in characters of the String representation (assuming the
  maximum allowed precision of the fractional seconds component). For
  binary data, this is the length in bytes. For the ROWID datatype, this
  is the length in bytes. Null is returned for data types where the
  column size is not applicable.

The maximum precision of a 32 bit integer is 10, the maximum precision of a 64 bit integer (long) is 19.
In other words, your assumption that COLUMN_SIZE contains the size in bytes is wrong. The getColumns result doesn't provide that information, except for character types in column CHAR_OCTET_LENGTH.
The definition of COLUMN_SIZE is derived from the X/Open SQL CLI, which in modified form lives on in the Call-Level Interface (SQL/CLI) standard (ISO-9075-3), specifically from the DescribeCol function (quoted from a draft of ISO-9075-3:2003):

b) Case:
    i) If the data type of C is character string, then ColumnSize is set to the maximum length in octets of C.
    ii) If the data type of C is exact numeric or approximate numeric, then ColumnSize is set to the maximum length of C in decimal digits.
    iii) If the data type of C is datetime or interval, then ColumnSize is set to the length in positions of C.
    iv) If the data type of C is a reference type, then ColumnSize is set to the length in octets of that reference type.
    v) Otherwise, ColumnSize is set to an implementation-dependent value.

