How to execute script file in Postgresql

In this article we are going to learn about executing the script file in PostgreSQL database.

Step1: Create file script file using cat command. cat > loginlist.dat and enter the following


cat > loginlist.dat

create user michael with password 'test@123'; create user philip with password 'test@123'; create user sachin with password 'tet@123'; create user federer with password 'test@123'; create user elchur with password 'great';

Then press ctrl+d option to save the file.

Step3: Now change permission of loginlist.dat file.

chmod 777 loginlist.dat

step4: switch to postgres
sudo su postgres

step5: Execute the script from unix host

postgres@ubuntu:/home/vijay$ psql postgres -f loginlist.dat psql:loginlist.dat:1: ERROR: role "michael" already exists CREATE ROLE CREATE ROLE CREATE ROLE CREATE ROLE postgres@ubuntu:/home/vijay$

The above script created 4 users and one failed. Because user ‘michael’ already exists.

Step5:
Verification.

Connect to postgresql using psql as shown below and run \du command to reflect above logins created successfully or not.

List of logins:

Related Posts

CheapSexCams
Responses are currently closed, but you can trackback from your own site.

Comments are closed.

Powered by k2schools
%d bloggers like this: