postgresql-check-db-dir 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #!/bin/sh
  2. # This script verifies that the postgresql data directory has been correctly
  3. # initialized. We do not want to automatically initdb it, because that has
  4. # a risk of catastrophic failure (ie, overwriting a valuable database) in
  5. # corner cases, such as a remotely mounted database on a volume that's a
  6. # bit slow to mount. But we can at least emit a message advising newbies
  7. # what to do.
  8. PGDATA="$1"
  9. if [ -z "$PGDATA" ]
  10. then
  11. echo "Usage: $0 database-path"
  12. exit 1
  13. fi
  14. # PGMAJORVERSION is major version
  15. PGMAJORVERSION=10
  16. # PREVMAJORVERSION is the previous major version
  17. PREVMAJORVERSION=9.6
  18. # Check for the PGDATA structure
  19. if [ -f "$PGDATA/PG_VERSION" ] && [ -d "$PGDATA/base" ]
  20. then
  21. # Check version of existing PGDATA
  22. if [ x`cat "$PGDATA/PG_VERSION"` = x"$PGMAJORVERSION" ]
  23. then
  24. : A-OK
  25. elif [ x`cat "$PGDATA/PG_VERSION"` = x"$PREVMAJORVERSION" ]
  26. then
  27. echo $"An old version of the database format was found."
  28. echo $"type postgresql_db_yukselt.sh"
  29. exit 1
  30. else
  31. echo $"An old version of the database format was found."
  32. echo $"You need to dump and reload before using PostgreSQL $PGMAJORVERSION."
  33. echo $"See http://www.postgresql.org/docs/$PGMAJORVERSION/static/upgrading.html"
  34. exit 1
  35. fi
  36. else
  37. # No existing PGDATA! Warn the user to initdb it.
  38. echo $"\"$PGDATA\" is missing or empty. Use a command like"
  39. echo $" su - postgres -c \"initdb --locale en_US.UTF-8 -D '$PGDATA'\""
  40. echo $"with relevant options, to initialize the database cluster."
  41. exit 1
  42. fi
  43. exit 0