Postgresql
<p>It is a basic database schema for managing information related to companies, hotels, rooms, features, attributes, customers, and reservations. The SQL script defines the table structure for each entity along …
python
create table company(
id serial primary key not null,
name varchar(200),
image varchar(200) null,
created_at timestamp not null default now(),
updated_at timestamp not null default now(),
"order" int not null default 0,
is_published BOOLEAN NOT NULL default False,
is_active BOOLEAN NOT NULL default True
);
create index idx_company_order company("order");
Jul 28, 2023
python
Postgresql
<p>The SQL query you provided is used to calculate and display the size of a PostgreSQL database named 'database_name' in a human-readable format. The function <code>pg_database_size()</code> returns the size of …
python
SELECT pg_size_pretty( pg_database_size('database_name') );
Jul 07, 2023
python
Postgresql
<p>The SQL code you provided creates several tables to implement a basic user, group, and permission system. Let's break down each table and its purpose:</p> <ol> <li> <p><code>public.user</code> table:</p> <ul> …
python
create table public.user(
id serial primary key not null,
name varchar(200),
created_at timestamp not null default now(),
updated_at timestamp not null default now(),
is_active BOOLEAN NOT NULL default True
);
create table public.group(
id serial primary key not null,
name varchar(200),
created_at timestamp not null default now(),
Oct 02, 2021
python
Postgresql
<ol> <li> <p><code>country</code> Table:</p> <ul> <li>This table stores information about countries.</li> <li>It has a primary key <code>id</code>, a <code>name</code> field to store the country name, and various timestamp fields (<code>created_at</code> …
python
create table country(
id serial primary key not null,
name varchar(200),
created_at timestamp not null default now(),
updated_at timestamp not null default now(),
"order" int not null default 0,
is_published BOOLEAN NOT NULL default False,
is_active BOOLEAN NOT NULL default True
);
create table vat(
Jan 02, 2021
python
Postgresql
Backup postgres databases
python
#!/bin/bash
logfile="/home/user/pgsql.log"
backup_dir="/home/user/backup"
touch $logfile
databases=`psql -h localhost -U postgres -q -c "\l" | sed -n 4,/\eof/p | grep -v rows\) | grep -v template0 | grep -v template1 | awk {'print $1'}`
echo "Starting backup of databases " >> $logfile
for i in $databases; do
dateinfo=`date '+%Y-%m-%d %H:%M:%S'`
timeslot=`date '+%Y%m%d%H%M'`
/usr/bin/vacuumdb -z -h localhost -U postgres $i >/dev/null 2>&1
/usr/bin/pg_dump -U postgres -F c -b $i -h 127.0.0.1 -f $backup_dir/$i-database-$timeslot.backup
Jul 25, 2019
python