What's new

Closed Prosgresql psql bash script or codes (Creating Database)

Status
Not open for further replies.

banal21

Eternal Poster
Joined
Feb 12, 2017
Posts
492
Reaction
1,395
Points
321
Age
33
Patulong lods. Di ko talaga makuha. Ito nalang ang naka manual sa aking script.
Paano po mag create ng database sa psql?
Paano po mag create ng user na may pass sa psql?
Paano po mag Grant all privelage sa psql?

Kapag manual kaya ko pong gawin sa terminal. Pero sa script ko. Huminto po sa siya sa postgres=# area at kelangan ko pang ilagay itong aking mga commands;
postgres=# CREATE USER myuser WITH PASSWORD 'mypassword';
postgres=# CREATE DATABASE mydatabase;
postgres=# GRANT ALL PRIVILEGES ON DATABASE mydatabase to myuser;
postgres=# \q

Anong script po ang pwede dito para automated na? Thanks po mga lods.
 
Once installed po Yung postgres libraries, mero po itong kasamang "createdb" function na pwede e Call sa bash directly.

You do not have permission to view the full content of this post. Log in or register now.

From there pwede Kang mag create nang bash script without going inside postgres shell if gusto mong e one script o hawing semi automated
 
Once installed po Yung postgres libraries, mero po itong kasamang "createdb" function na pwede e Call sa bash directly.

You do not have permission to view the full content of this post. Log in or register now.

From there pwede Kang mag create nang bash script without going inside postgres shell if gusto mong e one script o hawing semi automated
Wala pong chance na maging fully automated po lods? Thanks po sa advise nagawa ko na po. Naka create po ng automatic mula sa bash script ko ng dbname at user. Pero may prompted password pong lumabas. Itong prompted password tumitigil po yung command sa bash script ko para ilagay ang pass. Tapos po pati po grant all privelages di po mabasa ng command sa script. May idea po ba kayo dito pano ito maging automatic? Salamat po ulit lods.
 
If that is the case po, pwede pong mag set/provide Yung env variable PGPASSWORD before sa actual script po(not suggested since madaling Makita Yung password). Also Hindi na ata needed Yung grant if you just provide the owner of the db(by DB default owner has all perms)

Bash:
PGPASSWORD=<psql password> createdb <db_name> -O <db_owner> -U <psql username>
 
Status
Not open for further replies.

Similar threads

Back
Top