Install postgresql
brew install postgresql@14Start postgresql as a service
brew services start postgresql@14Check if postgres is running
psql --versionIf you don’t want PostgreSQL to run as a service, you can start it manually:
pg_ctl -D /opt/homebrew/var/postgres startStop the service
brew services stop postgresRestart the service
brew services restart postgresList all running services
brew services listLogin to postgres
psql postgresCreate User
CREATE USER app_user WITH PASSWORD app_password;Alter role
ALTER ROLE app_user CREATE_DB;check all users
\duExit using CTRL+D
Login using new user
psql postgres -u app_usercreate Database
CREATE DATABASE app_databaseTo check all databases
\lconnect to db
\connect app_databaselist all tables
\dlcheck table definition
\d table_nameOnce you are connected to the database, you can run the SQL script file using the following command
\i /path/to/your/script.sqlyou can exit the psql interface by typing
\q
Once you're connected, you can use the COPY command to import the CSV file. The basic syntax is:
COPY table_name FROM '/path/to/your/file.csv' DELIMITER ',' CSV HEADER;
Top comments (0)