PORT 23803 DIR db FULLDIR pwd DIR LOGFILE DIR db log DBNAME test MYUSE

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
PORT = 23803
DIR = db
FULLDIR = `pwd`/$(DIR)
LOGFILE = $(DIR)/db.log
DBNAME = test
MYUSER = `whoami`
default: run
pgainstall: installdb rebuildpghba installmyuser reload
installdb: clean
mkdir -p $(FULLDIR)
initdb -D $(FULLDIR)
pg_ctl -D $(FULLDIR) -l $(LOGFILE) -o "-i -p $(PORT) -D $(FULLDIR)" start
sleep 20
createdb -p $(PORT) $(DBNAME)
createlang -p $(PORT) plpgsql $(DBNAME)
rebuildpghba:
mv $(FULLDIR)/pg_hba.conf $(FULLDIR)/pg_hba.conf.bak
head --lines=-6 $(FULLDIR)/pg_hba.conf.bak>$(FULLDIR)/pg_hba.conf
printf "local\tall\t%s\t\ttrust\n">>$(FULLDIR)/pg_hba.conf $(MYUSER)
printf "host\tall\t%s\t127.0.0.1/32\ttrust\n">>$(FULLDIR)/pg_hba.conf $(MYUSER)
printf "host\tall\t%s\t::1/128\ttrust\n">>$(FULLDIR)/pg_hba.conf $(MYUSER)
installmyuser:
printf "host\t%s\t%s\t192.168.0.0\t255.255.0.0\ttrust\n" $(DBNAME) $(MYUSER)>>$(FULLDIR)/pg_hba.conf
start:
pg_ctl -D $(FULLDIR) -l $(LOGFILE) -o "-i -p $(PORT) -D $(FULLDIR)" start
stop:
pg_ctl -D $(FULLDIR) -l $(LOGFILE) -o "-i -p $(PORT) -D $(FULLDIR)" stop
reload:
pg_ctl -D $(FULLDIR) -l $(LOGFILE) -o "-i -p $(PORT) -D $(FULLDIR)" reload
clean:
rm -rf $(FULLDIR)
run:
psql -p $(PORT) $(DBNAME)