Database Columns In Select or create statements [duplicate] - postgresql

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
What is the maximum number of columns in a PostgreSQL select query
I am going to start a new project which requires a large number of tables and columns , using postgres I just want to ask that is number of columns in creating postgres tables are limited , If yes then what would be the MAX value for number of columns in CREATE and SELECT statements?

Since Postgres 12, the official list of limitations can be found in the manual:
Item Upper Limit Comment
---------------------------------------------------------
database size unlimited
number of databases 4,294,950,911
relations per database 1,431,650,303
relation size 32 TB with the default BLCKSZ of 8192 bytes
rows per table limited by the number of
tuples that can fit onto 4,294,967,295 pages
columns per table 1600 further limited by tuple size fitting on a single page; see note below
field size 1 GB
identifier length 63 bytes can be increased by recompiling PostgreSQL
indexes per table unlimited constrained by maximum relations per database
columns per index 32 can be increased by recompiling PostgreSQL
partition keys 32 can be increased by recompiling PostgreSQL
Before that, there was an official list on the PostgresL "About" page. Quote for Postgres 9.5:
Limit Value
Maximum Database Size Unlimited
Maximum Table Size 32 TB
Maximum Row Size 1.6 TB
Maximum Field Size 1 GB
Maximum Rows per Table Unlimited
Maximum Columns per Table 250 - 1600 depending on column types
Maximum Indexes per Table Unlimited
If you get anywhere close to those limits, chances are you are doing something wrong.

Related

Redshift database size grew sagnificantly when the cluster was resized

In Redshift I had a cluster with 4 nodes of the type dc2.large
The total size of the cluster was 160*4=640gb. The system showed 100% storage full. The size of the database was close to 640gb
Query I use to check the size of the db:
select sum(used_mb) from (
SELECT schema as table_schema,
"table" as table_name,
size as used_mb
FROM svv_table_info d order by size desc
)
I added 2 dc2.large nodes - classic resize which set the size of the cluster to 160*6=960gb, but when I checked the size of the database suddenly I saw that it also grew and again takes almost 100% of the cluster with increased size.
Database size grew with the size of the cluster!
I had to perform additional resize operation - elastic one. From 6 nodes to 12 nodes. The size of the data remained close to 960gb
How is it possible that the size of the database grew from 640gb to 960gb as a result of cluster resize operation?
I'd guess that your database has a lot of small tables in it. There are other ways this can happen but this is by far the most likely cause. You see Redshift uses a 1MB "block" as the minimum storage unit which is great for large data table storage but is inefficient for small (< 1M rows per slice in the cluster).
If you have a table that has say 100K rows split across your 4 nodes of dc2.large nodes (8 slices), each slice holds 12.5K rows. Each column for this table will need 1 block (1MB) to store the data. However, a block on average can store 200K rows (per column) so most of the blocks for this table are mostly empty. If you add rows the on-disk size (post vacuum) doesn't increase. Now if you add 50% more nodes you are also adding 50% more slices which just adds 50% more nearly empty blocks to the table's storage.
If this isn't your case I can expand on other ways this can happen but this really is the most likely in my experience. Unfortunately the fix for this is often to revamp your data model or to offload some less used data to Spectrum (S3).

Zero for indexes

When I do select * from pg_stat_user_indexes on one of the tables in production, 2 indexes are showing zero for all 3 columns idx_scan, idx_tup_read and idx_tup_fetch.
One of the indexes is showing size of 12GB and the other one around 6.5 GB.
Does it mean, this indexes is not used?
Postgres version 11.8

Size of the table is growing abnormally in postgres database

One of our database size is 50gb. Out of it one of the table has 149444622 records. Size of that table is 14GB and its indexes size is 16GB.
Total size of the table and its indexes are 30GB. I have perfomred the below steps on that table.
reindex table table_name;
vacuum full verbose analyze on table_name;
But still the size of the table and its indexes size are not reduced. Please guid me. How to proceed further.
Structure of the table as below.
14 GB for your data is not abnormal. Let's do the math.
Simply adding up the sizes of your columns gives 68 bytes per column.
2 bigints # 8 bytes each 16 bytes
4 integers # 4 bytes each 16 bytes
4 doubles # 8 bytes each 32 bytes
1 date # 4 bytes 4 bytes
--------
68 bytes
149,444,622 at 68 bytes each is about 9.7 GB. This is the absolute minimum size of your data if there were no database overhead. But there is overhead. This answer reckons its about 28 bytes per row. 68 + 28 is 96 bytes per row. That brings us to... 14.3 GB. Just what you have.
I doubt you can reduce the size without changing your schema, dropping indexes, or deleting data. If you provided more detail about your schema we could give suggestions, but I would suggest doing that as a new question.
Finally, consider that 50 GB is a pretty small database. For example, the smallest paid database offered by Heroku is 64 GB and just $50/month. This may be a situation where it's fine to just use a bigger disk.

use hbase to export/import a table data between two clusters, The size of two tables and the number of rows are inconsistent

The first table size is 10G with 8 million rows, but imported table size is 8G with 6 million rows. Why is there so much less data?

Maximum data size for table per row

According to documentation
Maximum Columns per Table 250 - 1600 depending on column types
Ok, but if have less than 250 columns, but several they contains really big data, many text type columns and many array type columns (with many elements), then there is any limit?
Question is: there is any size limit for per row? (sum of all columns content).