-- Task 1.1 - Find the settings in PostgreSQL (1 pts) SELECT name, setting, category FROM pg_settings ORDER BY category, name; -- Task 1.2 - Create a User (1 pts) CREATE USER username WITH ENCRYPTED PASSWORD 'password' VALID UNTIL 'YYYY-MM-DD'; -- Task 1.3 - Create a Role (1 pts) CREATE ROLE rolename WITH LOGIN PASSWORD 'password' IN ROLE parent_role; -- Task 1.4 - Grant privileges to the role (2 pts) GRANT SELECT, INSERT, UPDATE ON table_name TO role_name; -- Task 1.5 - Grant role to a user (1 pts) GRANT role_name TO username; -- Task 1.6 - Backup a database on PostgreSQL server (1 pts) pg_dump -U username -h hostname -F c -b -f /path/to/backup_file dbname; -- Task 2.1 - Restore MySQL server using a previous backup (1 pts) mysql -u username -p dbname < /path/to/backup_file.sql; -- Task 2.2 - Find the table data size (1 pts) SELECT pg_size_pretty(pg_total_relation_size('schema_name.table_name')); -- Task 2.3 - Baseline query performance (1 pts) EXPLAIN (ANALYZE, BUFFERS, VERBOSE) your_query; -- Task 2.4 - Create an index (1 pts) CREATE INDEX CONCURRENTLY index_name ON table_name USING btree (column_name); -- Task 2.5 - Document the improvement in query performance (1 pts) EXPLAIN (ANALYZE, BUFFERS, FORMAT JSON) your_query; -- Task 2.6 - Find supported storage engines (1 pts) SHOW default_storage_engine; -- Task 2.7 - Find the storage engine of a table (1 pts) SHOW TABLE STATUS WHERE Name = 'table_name'; -- Task 3.1 - Restore the table billing (2 pts) pg_restore -U username -h hostname -d dbname -v /path/to/backup_file; -- Task 3.2 - Create a view named basicbilldetails (1 pts) CREATE VIEW basicbilldetails AS SELECT customerid, month, billedamount FROM billing; -- Task 3.3 - Baseline query performance (1 pts) EXPLAIN (ANALYZE, BUFFERS, VERBOSE) your_query; -- Task 3.4 - Create an index (1 pts) CREATE INDEX CONCURRENTLY index_name ON table_name USING btree (column_name); -- Task 3.5 - Document the improvement in query performance (1 pts) EXPLAIN (ANALYZE, BUFFERS, FORMAT JSON) your_query;
Write, Run & Share PostgreSQL queries online using OneCompiler's PostgreSQL online editor and compiler for free. It's one of the robust, feature-rich online editor and compiler for PostgreSQL. Getting started with the OneCompiler's PostgreSQL editor is really simple and pretty fast. The editor shows sample boilerplate code when you choose database as 'PostgreSQL' and start writing queries to learn and test online without worrying about tedious process of installation.
PostgreSQL is a open source relational database system and is also knows as Postgres.
CREATE command is used to create a table, schema or an index.
CREATE TABLE table_name (
column1 datatype,
column2 datatype,
....);
ALTER command is used to add, modify or delete columns or constraints from the database table.
ALTER TABLE Table_name ADD column_name datatype;
TRUNCATE command is used to delete the data present in the table but this will not delete the table.
TRUNCATE table table_name;
DROP command is used to delete the table along with its data.
DROP TABLE table_name;
RENAME command is used to rename the table name.
ALTER TABLE table_name1 RENAME to new_table_name1;
INSERT Statement is used to insert new records into the database table.
INSERT INTO table_name (column1, column2, column3, ...) VALUES (value1, value2, value3, ...);
Select statement is used to select data from database tables.
SELECT column1, column2, ...
FROM table_name;
UPDATE statement is used to modify the existing values of records present in the database table.
UPDATE table_name
SET column1 = value1, column2 = value2, ...
WHERE condition;
DELETE statement is used to delete the existing records present in the database table.
DELETE FROM table_name where condition;