in reply to Re^3: Database access and async web framework (like Mojolicious)
in thread Database access and async web framework (like Mojolicious)
ok, thanks, i am doing that. su is my friend.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: Database access and async web framework (like Mojolicious)
by bliako (Abbot) on Dec 18, 2024 at 11:16 UTC | |
bummer, I need to double quote all my existing db-ops scripts to account for the extra 'su -c ...' and just now I found that 'create database' does not support 'IF NOT EXIST' and that I have to go in a huge roundabout involving some creature called \gexec which after an hour I found out it is not supported in 'psql -c ...'. Hey I think I have found in PG a new sadomasochistic group. Whips! yummy not. Edit: psql -Upostgres will run the commands via the 'postgres' linux user. I thought it runs the SQL commands via a db user. OK now I can avoid the constant su but I have to enter password all the time! So better running the script via su -c db-init-script.sh - postgres. | [reply] [d/l] [select] |
by bliako (Abbot) on Dec 23, 2024 at 16:29 UTC | |
OK, it seems I had some progress sanEtising my interactions with postgres and psql, its sql shell. Once I create a database and a database user I no longer need to use the "postgres" linux account to run commands via su thanks to the "service file". This is a simple configuration file which holds dbname, dbuser, pass etc.:
And then PGSERVICEFILE=x/y/z.config psql 'service=myservice' I have also found that psql accepts a connection string like: sql 'postgresql://mydbuser:mypassword@host:port/mydbname' (host, port are optional, leave empty for unix socket connection) | [reply] [d/l] [select] |
by cavac (Prior) on Jan 09, 2025 at 13:34 UTC | |
It's also possible to run Perl scripts within the database (using the extension 'plperl' or 'plperlu'. This is quite useful for performance optimization, writing complex triggers and such. But it's also quite nice for debugging and administration, if you can run certain scripts just by selecting from them. A basic data generator could look like this:
Now you can use the function like a read-only table:
Of course, plperl can also run SQL statements, access results and more, including to be used as a INSERT/UPDATE/DELETE trigger function. A simple example would be to make sure every customer entry has a customer number, avoiding the pitfalls of database sequences (which may leave big holes for cancelled transactions etc), something like this:
PerlMonks XP is useless? Not anymore: XPD - Do more with your PerlMonks XP Also check out my sisters artwork and my weekly webcomics | [reply] [d/l] [select] |
by erix (Prior) on Jan 10, 2025 at 06:08 UTC | |
by bliako (Abbot) on Jan 14, 2025 at 11:40 UTC | |
by vincent_veyron (Beadle) on Dec 19, 2024 at 18:53 UTC | |
Hey I think I have found in PG a new sadomasochistic group. Whips! yummy not. Haha! True, but once you are initiated, you'll be hooked. I know I was when this girlfriend of mine introduced me to bonding, but I digress. Postgresql's documentation is outstanding, and very easy to search. I suggest you invest some time to get the hang of it, by reading Chapter I Tutorial and investigating Chapter VI Reference, which will cover most your needs. The pgsql-general list is very active, you'll get all the help you need there, providing you did basic research. I've been reading it every day for twenty years, I learn something new every time. Marica : Logiciel de gestion des contentieux juridiques, des contrats et des sinistres d'assurance | [reply] |
by bliako (Abbot) on Dec 20, 2024 at 12:24 UTC | |
thanks, I will definetely persist with Pg | [reply] |