I need to get a list of tables for each tablespace. I listed the tablespaces and their containers, but I can't find a way to display which tables are related to each tablespace, I am only interested in 4 tablespaces, so I could do one at a time. Is there a query that I can run in db2 8.1?
Related
I have installed PostgreSQL 13.1 on two computers, a laptop and desktop.
I created database using a Tablespace on a portable SSD drive under F:\MyProject\DB\PG_13_202007201\20350. So I expect all the database files to be in there somewhere.
I want to work on the database on the SSD drive which is fine on the laptop that created the database, but when I go to my desktop I can't figure out how to attach (SQL Server style) the existing database/tablespace and continue working on it.
Is there a way to work like this with Postgresql?
You cannot do that.
A tablespace contains just the data files, but essential information is stored in the metadata (the table name, the columns and their data type, constraints, ...) and elsewhere (for example, the commit log determines which table entries you can see and which ones you cannot).
In short, a tablespace is not self-contained, and you cannot use a tablespace from one database cluster with another database cluster.
If you want to move data between databases, use pg_dump.
I have many tables/schemas distributed among many tablespaces.
Are there any queries exist/you have found or invented to figure out, which table(s) and misc. belong to which tablespaces and visa-versa (which tablespaces belong to which tables and misc.)?
Thank you for share/reply.
What is the hierarchy of Database related objects in postgres SQL?
Should it be like, table space must be created at instance level unlike other RDBMS(where we have table space under database).
If so we create the table space at instance level, what is the purpose of database? and what is difference between table space and database on postgres server?
An instance (in PostgreSQL called cluster) is a data directory initialized with initdb with a PostgreSQL server process.
A tablespace is a directory outside the data directory where objects can also be stored. Tablespaces are useful for certain corner cases like distributing I/O or limiting space for a subset of the data.
A database is a container for objects with permissions, organized in schemas.
The difference is that tablespaces are a physical concept, it defines a space where the data are stored, while databases are a logical concept about how data are organized, what they mean, how they are related, who is allowed to access them and so on.
The two concepts are orthogonal.
A database can have tables in several tablespaces, and a tablespace can contain data from several databases.
Database is where you organize all your objects. Tablespace is just storage space for those object.
You can storage your db object in different Tablespace. For example one table is storage in a Tablespace in diskA but another Table use a Tablespace in diskB to improve the performance. Or maybe you need a tablespace for big tables and dont mind use a slow big HDD for those objects.
I have two databases, db1 and db2,
each has a able. The two databases have the same data in each table.
For the databases remain the same, I need a trigger that causes, when inserting a new data table in db1, this same data is inserted into db2 table simultaneously, thus keeping the two databases always equal.
There tables are equal.
Google Slony, that's it, now you have triggers and replicas.
The other way to do it, would be the streaming replication.
I am using PostgreSQL and I want to add a new data files to existing tablespace ( like in oracle )
I could not found any description on this on PostgreSQL documentation.
How to do this ?
PotgreSQL works different than Oracle. It has a much simpler concept for data storage. Data blocks, extents and segments don't exist. In the same spirit, a tablespace is not split into multiple data files. You just create the tablespace and PostgreSQL creates the necessary files to store the data.
When creating a tablespace, you can provide a location, where PostgreSQL should store the data:
CREATE TABLESPACE dbspace LOCATION '/data/dbs';
This works similar to bigfile tablespaces in Oracle, where you also don't have to manage data files.