« Info:: Postgresql » : différence entre les versions
De wiki_pcwiki2
Aller à la navigationAller à la recherche
Aucun résumé des modifications |
Aucun résumé des modifications |
||
| (13 versions intermédiaires par le même utilisateur non affichées) | |||
| Ligne 1 : | Ligne 1 : | ||
KEYWORDS: POSTGRESQL | KEYWORDS: POSTGRESQL | ||
[[INFO::postgresql:exemple de visualisation de la table NRGY_EVENTS]] Le 28/04/2026 | |||
'''Le 19/05/2026:''' | |||
Comment lister toutes les tables dans postgresql: | |||
- sur SRV18: | |||
export PAGER=less | |||
PAGER=less | |||
sudo -E -u postgres psql -U postgres -h 127.0.0.1 -c '\l' | |||
Mot de passe pour l'utilisateur postgres : | |||
ou: | |||
'''sudo -u postgres PGPASSWORD="fr...ce" psql -U postgres -h 127.0.0.1 -P pager=off -c '\l'''' | |||
ou alors: | |||
'''echo "127.0.0.1:5432:*:postgres:fr...ce" > /root/.pgpass;chmod 600 /root/.pgpass;chown root:root /root/.pgpass''' | |||
- sur OVH1: | |||
'''sudo -u postgres PGPASSWORD="fe...11" psql -U postgres -h 127.0.0.1 -P pager=off -c '\l'''' | |||
'''Le 21/04/2026:''' | '''Le 21/04/2026:''' | ||
Exemples donnés sur la base | Exemples donnés sur la base '''pcNrgy5''' (''clone de la base Mariadb pour '''WATTS_SPEED''''') | ||
<pre> | <pre> | ||
''- Pour éviter d'avoir à donner le pwd: réer le fichier (format : host:port:db:user:password)'' | |||
'''echo "127.0.0.1:5432:pcNrgy5:pcnrgy5:fromspace" > ~/.pgpass''' | |||
'''chmod 600 ~/.pgpass''' | |||
echo "127.0.0.1:5432:pcNrgy5:pcnrgy5:fromspace" > ~/.pgpass | |||
chmod 600 ~/.pgpass | |||
Pour avoir la liste des tables: | ''- Pour avoir la liste des tables:'' | ||
'''psql -U pcnrgy5 -d pcNrgy5 -h 127.0.0.1 -c '\d'''' | '''psql -U pcnrgy5 -d pcNrgy5 -h 127.0.0.1 -c '\d'''' | ||
Pour avoir les définitions d'une ou deux tables: | ''- Pour avoir les définitions d'une ou deux tables:'' | ||
'''psql -U pcnrgy5 -d pcNrgy5 -h 127.0.0.1 -c '\d nrgy_appliances'''' | '''psql -U pcnrgy5 -d pcNrgy5 -h 127.0.0.1 -c '\d "WATTS_SPEED"' '''' | ||
'''psql -U pcnrgy5 -d pcNrgy5 -h 127.0.0.1 -c '\d nrgy_appliances' ''' | |||
''- Pour blanchir une table: | |||
'''psql -U pcnrgy5 -d pcNrgy5 -h 127.0.0.1 -c "TRUNCATE autoconsommation" | |||
'''psql -U pcnrgy5 -d pcNrgy5 -h 127.0.0.1 -c '\d nrgy_events' -c '\d nrgy_patterns'''' | '''psql -U pcnrgy5 -d pcNrgy5 -h 127.0.0.1 -c '\d nrgy_events' -c '\d nrgy_patterns'''' | ||
Pour lancer une commande SQL: | ''- Pour lancer une commande SQL:'' | ||
'''psql -U pcnrgy5 -d pcNrgy5 -h 127.0.0.1 -c "SELECT label, phase, delta_w_min, delta_w_max, time_start, time_end, weight, duree_moy_sec FROM nrgy_patterns ORDER BY label LIMIT 20;"''' | '''psql -U pcnrgy5 -d pcNrgy5 -h 127.0.0.1 -c "SELECT label, phase, delta_w_min, delta_w_max, time_start, time_end, weight, duree_moy_sec FROM nrgy_patterns ORDER BY label LIMIT 20;"''' | ||
'''psql -U pcnrgy5 -d pcNrgy5 -h 127.0.0.1 -c "SELECT * FROM nrgy_appliances_plages;"''' | '''psql -U pcnrgy5 -d pcNrgy5 -h 127.0.0.1 -c "SELECT * FROM nrgy_appliances_plages;"''' | ||
'''psql -U pcnrgy5 -d pcNrgy5 -h 127.0.0.1 -c "SELECT a.id, a.label, a.phase, p.plage_debut, p.plage_fin FROM nrgy_appliances a LEFT JOIN nrgy_appliances_plages p ON p.appliance_id = a.id ORDER BY a.id;"''' | '''psql -U pcnrgy5 -d pcNrgy5 -h 127.0.0.1 -c "SELECT a.id, a.label, a.phase, p.plage_debut, p.plage_fin FROM nrgy_appliances a LEFT JOIN nrgy_appliances_plages p ON p.appliance_id = a.id ORDER BY a.id;"''' | ||
'''psql -U pcnrgy5 -d pcNrgy5 -h 127.0.0.1 -c "SELECT id, label, actif FROM nrgy_appliances WHERE actif = 0;" | '''psql -U pcnrgy5 -d pcNrgy5 -h 127.0.0.1 -c "SELECT id, label, actif FROM nrgy_appliances WHERE actif = 0;" | ||
''' | ''' | ||
Dernière version du 19 mai 2026 à 07:37
KEYWORDS: POSTGRESQL
INFO::postgresql:exemple de visualisation de la table NRGY_EVENTS Le 28/04/2026
Le 19/05/2026: Comment lister toutes les tables dans postgresql: - sur SRV18: export PAGER=less PAGER=less sudo -E -u postgres psql -U postgres -h 127.0.0.1 -c '\l' Mot de passe pour l'utilisateur postgres : ou: sudo -u postgres PGPASSWORD="fr...ce" psql -U postgres -h 127.0.0.1 -P pager=off -c '\l' ou alors: echo "127.0.0.1:5432:*:postgres:fr...ce" > /root/.pgpass;chmod 600 /root/.pgpass;chown root:root /root/.pgpass - sur OVH1: sudo -u postgres PGPASSWORD="fe...11" psql -U postgres -h 127.0.0.1 -P pager=off -c '\l'
Le 21/04/2026: Exemples donnés sur la base pcNrgy5 (clone de la base Mariadb pour WATTS_SPEED)
- Pour éviter d'avoir à donner le pwd: réer le fichier (format : host:port:db:user:password) echo "127.0.0.1:5432:pcNrgy5:pcnrgy5:fromspace" > ~/.pgpass chmod 600 ~/.pgpass - Pour avoir la liste des tables: psql -U pcnrgy5 -d pcNrgy5 -h 127.0.0.1 -c '\d' - Pour avoir les définitions d'une ou deux tables: psql -U pcnrgy5 -d pcNrgy5 -h 127.0.0.1 -c '\d "WATTS_SPEED"' ' psql -U pcnrgy5 -d pcNrgy5 -h 127.0.0.1 -c '\d nrgy_appliances' - Pour blanchir une table: psql -U pcnrgy5 -d pcNrgy5 -h 127.0.0.1 -c "TRUNCATE autoconsommation" psql -U pcnrgy5 -d pcNrgy5 -h 127.0.0.1 -c '\d nrgy_events' -c '\d nrgy_patterns' - Pour lancer une commande SQL: psql -U pcnrgy5 -d pcNrgy5 -h 127.0.0.1 -c "SELECT label, phase, delta_w_min, delta_w_max, time_start, time_end, weight, duree_moy_sec FROM nrgy_patterns ORDER BY label LIMIT 20;" psql -U pcnrgy5 -d pcNrgy5 -h 127.0.0.1 -c "SELECT * FROM nrgy_appliances_plages;" psql -U pcnrgy5 -d pcNrgy5 -h 127.0.0.1 -c "SELECT a.id, a.label, a.phase, p.plage_debut, p.plage_fin FROM nrgy_appliances a LEFT JOIN nrgy_appliances_plages p ON p.appliance_id = a.id ORDER BY a.id;" psql -U pcnrgy5 -d pcNrgy5 -h 127.0.0.1 -c "SELECT id, label, actif FROM nrgy_appliances WHERE actif = 0;"