[SQL] 어떻게 hstore 확장자를 가진 새 데이터베이스가 이미 설치를 만드는 방법?
SQL어떻게 hstore 확장자를 가진 새 데이터베이스가 이미 설치를 만드는 방법?
최근에 나는 장고 hstore를 사용하려고 문제로 갔다. 나는 hstore 이런 식으로 설치 :
$ sudo -u postgres psql
postgres=# CREATE EXTENSION hstore;
WARNING: => is deprecated as an operator name
DETAIL: This name may be disallowed altogether in future versions of PostgreSQL.
CREATE EXTENSION
postgres=# \dx
List of installed extensions
Name | Version | Schema | Description
---------+---------+------------+--------------------------------------------------
hstore | 1.0 | public | data type for storing sets of (key, value) pairs
plpgsql | 1.0 | pg_catalog | PL/pgSQL procedural language
(2 rows)
그리고 순진 나의 새로운 데이터베이스가 hstore을 포함 할 것이라고 생각했다. 그건 사실이 아니다 :
$ createdb dbtest
$ psql -d dbtest -c '\dx'
List of installed extensions
Name | Version | Schema | Description
---------+---------+------------+------------------------------
plpgsql | 1.0 | pg_catalog | PL/pgSQL procedural language
(1 row)
자동으로 새로 만든 데이터베이스에 hstore을 할 수있는 방법이 있습니까?
해결법
-
==============================
1.긴 이야기를 짧게 :
긴 이야기를 짧게 :
template1를 데이터베이스에 hstore를 설치합니다 :
psql -d template1 -c 'create extension hstore;'
단계별 설명 :
PostgreSQL의 문서에서 언급 한 바와 같이 :
확장을 설치하면 데이터베이스 다릅니다. 다음 반환하면 현재 데이터베이스의 이름을 :
$ psql -c 'select current_database()' current_database ------------------ username (1 row)
경우에 당신은 당신의 이름의 이름을 따서 명명 데이터베이스를 가지고있다. 이제 DBTEST과 :
$ psql -d dbtest -c 'select current_database()' current_database ------------------ dbtest (1 row)
좋아, 당신은 그것을 얻었다. 이제 hstore 설치와 함께, 당신은 template1를 데이터베이스에 설치해야합니다 새 데이터베이스를 만들 수 있습니다. 해당 문서에 따르면 :
이 해 보자 :
$ psql -d template1 -c 'create extension hstore;'
그리고 그것은 작동하는지 확인 :
$ createdb dbtest $ psql -d dbtest -c '\dx' List of installed extensions Name | Version | Schema | Description ---------+---------+------------+-------------------------------------------------- hstore | 1.0 | public | data type for storing sets of (key, value) pairs plpgsql | 1.0 | pg_catalog | PL/pgSQL procedural language (2 rows)
끝난!
from https://stackoverflow.com/questions/11584749/how-to-create-a-new-database-with-the-hstore-extension-already-installed by cc-by-sa and MIT license
'SQL' 카테고리의 다른 글
[SQL] SQL Server 2008의 데이터베이스로부터 데이터를 백업 하나의 테이블 (0) | 2020.05.31 |
---|---|
[SQL] 특정 값으로 VARCHAR () 열 제한? (0) | 2020.05.31 |
[SQL] 파라미터 문은 모든 SQL 주입을 중지 할 수 있습니까? (0) | 2020.05.31 |
[SQL] INITIALLY DEFERRABLE IMMEDIATE 대 NOT DEFERRABLE (0) | 2020.05.31 |
[SQL] MySQL은 - 왜 인덱스 모든 분야? (0) | 2020.05.31 |