myPostgresCreateGisDb.R 1.5 KB

1234567891011121314151617181920212223242526
  1. #' PostgreSQL - Create 'postgis' database
  2. #' @details Postgis'i andmebaasi loomine.
  3. #' @param host Name or the numeric IPaddress of the host to connect to.
  4. #' @param dbname The database name.
  5. #' @param user PostgreSQL user name to connect as. Defaults to be the same as the operating system name of the user running the application.
  6. #' @param password Password to be used if the server demands password authentication.
  7. #' @param port Port number to connect to at the server host.
  8. #' @return return message.
  9. #' @seealso \code{\link{myPostgresConnect}}, \code{\link{myPostgresDropTable}},
  10. #' \code{\link{myPostgresCreateGisDb}}, \code{\link{myPostgresImprotShp}}
  11. #' @examples \dontrun{
  12. #' con <- myPostgresCreateGisDb(host = '192.168.255.26', port = 5432,
  13. #' user = 'ardo', password = '247848', dbname = 'xxx')
  14. #'
  15. #' }
  16. #'
  17. #' @export
  18. #'
  19. myPostgresCreateGisDb <- function(host = '192.168.255.26', port = 5432, user = 'ardo', password = '247848', dbname = NULL) {
  20. if(is.null(dbname)) {message("Palun sisesta andmebaasi nimi!"); return(NULL)}
  21. system(paste0("export PGPASSWORD='", password, "' && createdb -U ", user, " -h ", host, " -p ", port, " ", dbname, ";"))
  22. # "psql -U ardo -h 192.168.255.26 -p 5432 -d shp -c 'CREATE EXTENSION hstore; CREATE EXTENSION postgis;'"
  23. system(paste0("export PGPASSWORD='", password, "' && psql -U ", user, " -d ", dbname, " -h ", host, " -p ", port, " -c 'CREATE EXTENSION hstore; CREATE EXTENSION postgis;'"))
  24. message(paste0("Genereeriti postgis'i andmebaas ", dbname, "."))
  25. }