0
0
PostgreSQLquery~20 mins

Creating databases and connecting in PostgreSQL - Practice Exercises

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Database Creator Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2:00remaining
What is the output of this database creation query?
Consider the following SQL command executed in PostgreSQL:

CREATE DATABASE testdb WITH OWNER = alice ENCODING = 'UTF8' CONNECTION LIMIT = 5;

What will be the result of this command?
PostgreSQL
CREATE DATABASE testdb WITH OWNER = alice ENCODING = 'UTF8' CONNECTION LIMIT = 5;
ASyntax error due to incorrect use of CONNECTION LIMIT.
BError because owner 'alice' does not exist.
CDatabase 'testdb' is created but with default encoding and unlimited connections.
DDatabase 'testdb' is created with owner 'alice', UTF8 encoding, and max 5 connections.
Attempts:
2 left
💡 Hint
Check the syntax for CREATE DATABASE and the parameters allowed.
📝 Syntax
intermediate
1:30remaining
Identify the syntax error in this database connection command
Which option shows a correct way to connect to a PostgreSQL database named 'shopdb' using psql command line?
Apsql -d shopdb -U admin
Bpsql --database shopdb --user admin
Cpsql -database shopdb -user admin
Dpsql -db shopdb -username admin
Attempts:
2 left
💡 Hint
Check the correct short options for database and user in psql.
optimization
advanced
2:00remaining
Which command optimizes database creation for a template?
You want to create a new database 'analytics' that is an exact copy of an existing database 'template_db'. Which command achieves this efficiently?
ACREATE DATABASE analytics COPY template_db;
BCREATE DATABASE analytics AS template_db;
CCREATE DATABASE analytics TEMPLATE template_db;
DCREATE DATABASE analytics CLONE template_db;
Attempts:
2 left
💡 Hint
PostgreSQL supports creating a database from a template using a specific keyword.
🔧 Debug
advanced
1:30remaining
Why does this connection attempt fail?
A user tries to connect to PostgreSQL using:

psql -d salesdb -U john

But gets the error:

psql: FATAL: role "john" does not exist

What is the most likely cause?
AThe database 'salesdb' does not exist.
BThe user 'john' has not been created as a PostgreSQL role.
CThe password for 'john' is incorrect.
DThe psql command is missing the host parameter.
Attempts:
2 left
💡 Hint
The error message mentions the role does not exist.
🧠 Conceptual
expert
2:30remaining
What is the effect of connecting to a database with the wrong encoding?
If a client connects to a PostgreSQL database that was created with ENCODING = 'UTF8' but the client uses a different encoding like LATIN1, what is the most likely outcome?
AData sent or received may be corrupted or cause errors due to encoding mismatch.
BPostgreSQL automatically converts all data to the client encoding without issues.
CThe connection will be refused by the server immediately.
DThe database encoding changes to match the client encoding for the session.
Attempts:
2 left
💡 Hint
Think about how character encoding affects data interpretation.