Postgresql – How to predict the growth of a PostgreSQL database

database-designmanagementpostgresql

I'm looking for a way to predict growth of the database given its fields, indexes, constraints (as foreign key), number of lines, and so.

I searched on Google, but I found only means to determine the actual space occupied by the database, and can not predict their growth.

For example, how can I determine how many bytes would be occupied on disk for the following tables, in the following cases

1) 100,000 rows in the account table, 10 rows in the role table and 100,000 lines in account_role table.

2) 500,000 lines per account table, 20 lines on paper table and 600,000 rows in the table account_role?

CREATE TABLE account(
    user_id serial PRIMARY KEY,
    username VARCHAR (50) UNIQUE NOT NULL,
    password VARCHAR (50) NOT NULL,
    email VARCHAR (355) UNIQUE NOT NULL,
    created_on TIMESTAMP NOT NULL,
    last_login TIMESTAMP
);

CREATE INDEX username_index ON COMPANY (username);


CREATE TABLE role(
    role_id serial PRIMARY KEY,
    role_name VARCHAR (255) UNIQUE NOT NULL
);


CREATE TABLE account_role
(
  user_id integer NOT NULL,
  role_id integer NOT NULL,
  grant_date timestamp without time zone,
  PRIMARY KEY (user_id, role_id),
  CONSTRAINT account_role_role_id_fkey FOREIGN KEY (role_id)
      REFERENCES role (role_id) MATCH SIMPLE
      ON UPDATE NO ACTION ON DELETE NO ACTION,
  CONSTRAINT account_role_user_id_fkey FOREIGN KEY (user_id)
      REFERENCES account (user_id) MATCH SIMPLE
      ON UPDATE NO ACTION ON DELETE NO ACTION
);

Best Answer

Well, for this part of your question:

I'm looking for a way to predict growth of the database given its fields, indexes, constraints (as foreign key), number of lines, and so.

I searched on Google, but I found only means to determine the actual space occupied by the database, and can not predict their growth.

It's not clear why monitoring pg_database_size(your_database_name) doesn't give you the information you are after. Plot the size of all your databases daily, fit a curve to the plot, and you should be able to come up with an estimate of when you need to buy more disk space. What else do you need to know, and why?

For this part of your question:

For example, how can I determine how many bytes would be occupied on disk for the following tables, in the following cases

1) 100,000 rows in the account table, 10 rows in the role table and 100,000 lines in account_role table.

2) 500,000 lines per account table, 20 lines on paper table and 600,000 rows in the table account_role?

You don't really need to concern yourself with how many rows are in each table or the precise structure of the table. Just query SELECT pg_total_relation_size('account'::regclass); and you have the answer, in bytes.