Vacuuming Postgresql has used up disk space - postgresql

I have just run Vacuum on a Postgres table to try to recover disk space, however the result is that all the disk space has been consumed. Does Vacuum crete log files or transaction logs that can be deleted?

I'm assuming you performed a VACUUM FULL as the standard VACUUM just makes space in the data file that is associated with deleted records free so that Postgres can use that space for new records. It doesn't release the space to the operating system.
VACUUM FULL does release space, but it does this by copying all the information that it wants to keep from the data file into a new data file, and then when complete it deletes the old data file. As such VACUUM FULL requires extra space while it is running.
http://www.postgresql.org/docs/current/static/sql-vacuum.html

Related

PostgreSQL: even read access changes data files disk leading to large incremental backups using pgbackrest

We are using pgbackrest to backup our database to Amazon S3. We do full backups once a week and an incremental backup every other day.
Size of our database is around 1TB, a full backup is around 600GB and an incremental backup is also around 400GB!
We found out that even read access (pure select statements) on the database has the effect that the underlying data files (in /usr/local/pgsql/data/base/xxxxxx) change. This results in large incremental backups and also in very large storage (costs) on Amazon S3.
Usually the files with low index names (e.g. 391089.1) change on read access.
On an update, we see changes in one or more files - the index could correlate to the age of the row in the table.
Some more facts:
Postgres version 13.1
Database is running in docker container (docker version 20.10.0)
OS is CentOS 7
We see the phenomenon on multiple servers.
Can someone explain, why postgresql changes data files on pure read access?
We tested on a pure database without any other resources accessing the database.
This is normal. Some cases I can think of right away are:
a SELECT or other SQL statement setting a hint bit
This is a shortcut for subsequent statements that access the data, so they don't have t consult the commit log any more.
a SELECT ... FOR UPDATE writing a row lock
autovacuum removing dead row versions
These are leftovers from DELETE or UPDATE.
autovacuum freezing old visible row versions
This is necessary to prevent data corruption if the transaction ID counter wraps around.
The only way to fairly reliably prevent PostgreSQL from modifying a table in the future is:
never perform an INSERT, UPDATE or DELETE on it
run VACUUM (FREEZE) on the table and make sure that there are no concurrent transactions

db2 Restored database size vs source database size

When a DB2 database is restored and recovered from backups
is the restored database a physical copy - ie: identical block for block with the source database (as it was at time of backup) - and of identical size of source database?
or
is the restored database a logical copy - where datafile blocks are reorganized and coalesced (so the most of unused, fragmented free space in datafiles has been removed - causing restored database to often be smaller in storage footprint?
It is a page-for-page physical copy, but only of the used extents of pages in each table space. You can not change the logical contents of the data during a restore but you could alter the layout of the physical persistent storage.
There are also some changes you can cause during the restore process which can affect the persistently stored state of the system, such as a redirected restore altering the table space definitions or storage groups, replacing the DB history file, changing the encryption method in use, or upgrading the DB to a new release level.
It's a page-for-page physical copy. (This is why you can't, for example, backup on a little-endian system and restore onto a big-endian system.)

PostgreSQL how to find what is causing Deadlock in vacuum when using --jobs parameter

How to find in PostgreSQL 9.5 what is causing deadlock error/failure when doing full vacuumdb over database with option --jobs to run full vacuum in parallel.
I just get some process numbers and table names... How to prevent this so I could successfuly do full vacuum over database in parallel?
Completing a VACUUM FULL under load is a pretty hard task. The problem is that Postgres is contracting space taken by the table, thus any data manipulation interferes with that.
To achieve a full vacuum you have these options:
Lock access to the vacuumed table. Not sure if acquiring some exclusive lock will help, though. You may need to prevent access to the table on application level.
Use a create new table - swap (rename tables) - move data - drop original technique. This way you do not contract space under the original table, you free it by simply dropping the table. Of course you are rebuilding all indexes, redirecting FKs, etc.
Another question is: do you need to VACUUM FULL? The only thing it does that VACUUM ANALYZE does not is contracting the table on the file system. If you are not very limited by disk space you do not need doing a full vacuum that much.
Hope that helps.

Error: 1105 in sql server

I'm using SOL server 2012 as database server.
Right now mdf file size is around 10 GB.
When ever I'm doing any transaction into this database sql server troughs bellow error
Error Number : 1105 Error Message :Could not allocate space for object dbo.tblsdr . PK_tblsdr_3213E83F0AD2A005 in database hwbsssdr because the PRIMARY filegroup is full.
Create disk space by deleting unneeded files, dropping objects in the filegroup, adding additional files to the filegroup, or setting autogrowth on for existing files in the file-group.
There is almost 400 GB of free space is available on my disc.
Can any one tell me what is the issue and how can i solve that.
Since you are using Express edition of SQL Server 2012, there is a limitations of 10GB per database, so this is your problem.
By the way, problem doesn't need necessarily to be with disk that is running out.
Also, if you have database with set up MAXSIZE to specific value, and if database reach that value every next transaction will report error from your question.
So, if you are sure that you have enough disk space for next transactions, check MAXSIZE property of your database executing next code:
use master;
go
exec sp_helpdb [YourDatabase]
If you want to change MAXSIZE database property, you can do this with next code:
alter database [YourDatabase]
modify file
(
name = 'YourDatabaseFile',
maxsize = X MB
)
Explanation
The specified filegroup has run out of free space.
Action
To gain more space, you can free disk space on any disk drive containing a file in the full filegroup, allowing files in the group to grow. Or you can gain space using a data file with the specified database.
Freeing disk space
You can free disk space on your local drive or on another disk drive. To free disk space on another drive:
Move the data files in the filegroup with an insufficient amount of free disk space to a different disk drive.
Detach the database by executing sp_detach_db.
Attach the database by executing sp_attach_db, pointing to the moved files.
Using a data file
Another solution is to add a data file to the specified database using the ADD FILE clause of the ALTER DATABASE statement. Or you can enlarge the data file by using the MODIFY FILE clause of the ALTER DATABASE statement, specifying the SIZE and MAXSIZE syntax.

How to set the table space of a sub select in PostgreSQL

I have a rather large Insert Query, and upon running this my slow disks fill up towards 100% upon where I revive:
Transaction aborted because DBD::Pg::db do failed: ERROR: could not write to hash-join temporary file: No space left on device
Sounds believable, I have a Fast drive with lots of space on it that i could use instead of the slow disk but I dont want to make the fast disk the default table-space or move the table im inserting into to the fast disk, I just want that data-blob that is generated as part of the insert query to be on the fast disk table-space. Is this possible is PostgreSQL and if so how?
version 9.1
You want the temp_tablespaces configuration directive. See the docs.
Temporary files for purposes such as sorting large data sets are also
created in these tablespaces
You must CREATE TABLESPACE the tablespace(s) before using them in an interactive SET temp_tablespaces command.
SET LOCAL temp_tablespaces may be used to set it only for the current transaction.