이콜레모 개발자 위키

Page history of PostgreSQL



Title: PostgreSQL | edited by Youngrok Pak at 10 years, 1 month ago.

<h2>기본 명령어</h2>
<h3>사용자 관련</h3>
<p>사용자 생성</p>
<pre>create role &lt;username&gt; with login password &lt;password&gt;;</pre>
<p>Super User</p>
<div class="post-text">
<pre class="lang-sql prettyprint prettyprinted"><code><span class="kwd">ALTER </span><span class="kwd">USER</span><span class="pln"> myuser </span><span class="kwd">WITH</span><span class="pln"> SUPERUSER</span><span class="pun">;</span></code></pre>
</div>
<p>권한 지정</p>
<pre>grant usage on schema public to &lt;username&gt;;<br>grant all on schema public to &lt;username&gt;;<br>grant all privileges on database &lt;dbname&gt; to &lt;username&gt;;<br>grant all on all tables in schema public to &lt;username&gt;<br>grant select on &lt;table&gt; to &lt;username&gt;;</pre>
<p>읽기 전용 계정 만들기 <a href="http://stackoverflow.com/questions/760210/how-do-you-create-a-read-only-user-in-postgresql">http://stackoverflow.com/questions/760210/how-do-you-create-a-read-only-user-in-postgresql</a></p>
<pre><code><span class="kwd">GRANT CONNECT ON DATABASE mydb TO xxx;<br>GRANT USAGE ON SCHEMA public TO xxx;<br>GRANT SELECT ON mytable TO xxx;<br>GRANT SELECT ON ALL TABLES IN SCHEMA public TO xxx;</span></code></pre>
<p>커넥션 현황 보기</p>
<pre>SELECT count(*) from pg_stat_activity;</pre>
<h3>데이터베이스 정보 보기</h3>
<p>데이터베이스 목록</p>
<pre><code>\l</code></pre>
<p>role 목록</p>
<pre><code>\du</code></pre>
<p>테이블, 뷰, 권한</p>
<pre>\dp</pre>
<h2>커맨드라인 명령어</h2>
<p> </p>
<h2><a href="파이썬">파이썬</a>에서 사용하기</h2>
<pre>import psycopg2<br>conn = psycopg2.connect('host=db.com user=youngrok password=blahblah dbname=mydb<br>cursor = conn.cursor()<br>cursor.execute('SELECT * FROM auth_user')<br>print cursor.fetchall()</pre>
<p> 
Wiki at WikiNamu