This is a sql project that manages a movie database.
Download the IMDB reduced dataset and extract the folder into our root path, the fold should be named as imdb-reduced
.
Create a file named logfile
in the log folder.
In the root path, initialize a Postgres disk area:
initdb -D ./data -E UTF8
Launch the postgreSQL server:
pg_ctl -D ./data -l ./log/logfile start
PostgreSQL create automatically a role with your user name on your operating system. We note it \$USER. Then we connect to the server using this role name.
psql -U $USER -d postgres
Make sure you have set the variable DATAPath
with the path of the folder data
(resp. LOGPath
with the path of the folder log
) in the PATH. Also there must be a PSQLPath
pointing to C:\Program Files\PostgreSQL\12\bin
if you install PostgreSQL in the default path.
In the root path, initialize a Postgres disk area using PowerShell:
& "$env:PSQLPath\initdb" -D $env:DATAPath -E UTF8
& "$env:PSQLPath\pg_ctl" -D $env:DATAPath -l "$env:LOGPath\logfile" start
if it fails. Try kill the process which occupies port 5432 (cf StackOverflow) in cmd running as Administator.
netstat -ano | findstr :5432
taskkill /PID <PID> /F
psql -U $env:UserName -d postgres
DROP SCHEMA public CASCADE;
CREATE SCHEMA public;
GRANT ALL ON SCHEMA public TO public;
postgres=# \i create.sql
postgres=# \o drop_command.sql
postgres=# \i hack_drop.sql
postgres=# \o
Then remove the redundant lines in drop_command.sql
.
postgres=# \o add_command.sql
postgres=# \i hack_create.sql
postgres=# \o
Then remove the redundant lines in add_command.sql
.
postgres=# \i drop_command.sql
Change the path correctly in your copy_for_loop.sql
, Then copy the data in csv file into database.
postgres=# \i copy_for_loop.sql
Add constraints.
postgres=# \i add_command.sql
Execute the queries.
postgres=# \i query.sql
Update the database.
postgres=# \i up.sql
To remove the change.
postgres=# \i down.sql
pg_ctl start -D ./data -l ./log/logFile.txt