I tried to look into data dictionary of postgresql for long time
but i didn't help.
I'm trying to know what state is the data file in, is it available for the db instance or not
photo with example
I tryed to look into pg_class table
Postgres does not have the concept of "online" (or "offline") data files.
When you create a table it creates a file for that table. For every GB of data, Postgres will add a new file. If you drop the table all files belonging to that table are removed.
So the files for a table are always "online".
For more details on how Postgres stores the data, I recommend reading the chapter Database Physical Storage in the manual.
Or read The Internals of PostgreSQL - Chapter 1: Database Cluster, Databases, and Tables
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.
If I am correct, SQLite stores a database per file, and a file can't store more than one databases.
How does PostgreSQL store a database in terms of file(s)? Does it also store a database per file, and a file can't store more than one databases?
(SQLite uses more than one file for the rollback journal or when in WAL mode.)
The PostgreSQL database file layout is documented in its documentation:
Each table and index is stored in a separate file. For ordinary relations, these files are named after the table or index's filenode number, which can be found in pg_class.relfilenode. […] in addition to the main file (a/k/a main fork), each table and index has a free space map …, which stores information about free space available in the relation. The free space map is stored in a file named with the filenode number plus the suffix _fsm. Tables also have a visibility map, stored in a fork with the suffix _vm, to track which pages are known to have no dead tuples. […]
I need to move some old data from one database to another - both have similar schemas. After the old rows in db1.mytable are inserted into db2.mytable - these same rows should be deleted from db1.mytable.
This is reduce db size and archive data that is not really needed that much but still important.
You should to use Foreign Data Wrapper for Postgres - https://www.postgresql.org/docs/current/static/postgres-fdw.html With foreign tables, you can send a query to another database.
I have installed graphite with PostgreSql db (https://www.digitalocean.com/community/tutorials/how-to-install-and-use-graphite-on-an-ubuntu-14-04-server)
Everything is great and I put some data in it. My question is, can I manage data in Postgres db? I have looked for tables with data in db, but I cant find them. Where are they? I just found only these tables.
table account_profile
table account_variable
table account_view
...
table django_content_type
table tagging_tag
table tagging_taggedi
Where are sent data exactly stored? Thanks.
According to the link you posted, Graphite is using the components called 'whisper' and 'Carbon' to store the data. The actual data are stored in this database component.
PostgreSQL is used for metadata by the Django-based web-frontend.
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.