我想知道是否有替代psql命令来测试使用bash连接到postgresql数据库.
我正在建立一个核心操作系统集群,并且有一个辅助服务,它应该执行相当于psql 'host=xxx port=xxx dbname=xxx user=xxx'每分钟的操作来确定服务是否正在运行,更重要的是,如果可以使用给定的参数连接到服务.
我无法直接在Core OS上安装postgres.通常在Core OS中使用的命令是类似的curl -f ${COREOS_PUBLIC_IPV4}:%i;.但它只告诉服务本身是否在给定端口上运行,没有任何访问检查.
先感谢您!
我有麻烦重新启动dockerized postgres数据库(我使用Core OS).使用该命令在bash脚本中启动数据库
# boot.sh
sudo -i -u postgres /usr/lib/postgresql/9.3/bin/postgres -D /var/lib/postgresql/9.3/main -c config_file=/etc/postgresql/9.3/main/postgresql.conf
Run Code Online (Sandbox Code Playgroud)
哪个有效.我有另一个由confd调用的脚本,当一些etcd键改变时运行(这部分没问题,文件被正确调用)并且必须重启postgres(不重新加载,因为一些配置更改需要重启).以下是我尝试的主要选项,但失败了...
# restart.sh
sudo -u postgres /usr/lib/postgresql/9.3/bin/pg_ctl --pgdata=/var/lib/postgresql/9.3/main restart
Run Code Online (Sandbox Code Playgroud)
系统地引发错误:
%FATAL: lock file "postmaster.pid" already exists
%HINT: Is another postmaster (PID 273) running in data directory "/var/lib/postgresql/9.3/main"?
Run Code Online (Sandbox Code Playgroud)
此外,
# restart.sh
rm /var/lib/postgresql/9.3/main/postmaster.pid
sudo -i -u postgres /usr/lib/postgresql/9.3/bin/postgres -D /var/lib/postgresql/9.3/main -c config_file=/etc/postgresql/9.3/main/postgresql.conf
Run Code Online (Sandbox Code Playgroud)
,
rm /var/lib/postgresql/9.3/main/postmaster.pid
/etc/init.d/postgresql start
Run Code Online (Sandbox Code Playgroud)
,
/etc/init.d/postgresql restart
Run Code Online (Sandbox Code Playgroud)
和
exec su postgres -c "/usr/lib/postgresql/9.3/bin/postgres -D /var/lib/postgresql/9.3/main -c config_file=/etc/postgresql/9.3/main/postgresql.conf"
Run Code Online (Sandbox Code Playgroud)
失败了
ERROR exit status 1
Run Code Online (Sandbox Code Playgroud)
任何想法?先感谢您!
基于以下问题(是否可以使用pip从私有github存储库安装包?),我尝试通过ssh连接到pip git存储库.
我的关键是自定义路径.我尝试导入它没有成功,总是以
Command /usr/bin/git clone -q ssh://git@bitbucket.org:<user>/<repo>.git /tmp/pip-rYrupA-build failed with error code 128 in None
Run Code Online (Sandbox Code Playgroud)
我试着登录
pip install git+ssh://git@bitbucket.org:<user>/<repo>.git -i /path/to/id_rsa
Run Code Online (Sandbox Code Playgroud)
没有成功.谢谢!
我想知道是否可以使用 TestCase 或 LiveServerTestCase 运行 django 测试来模拟多个服务器的存在。
例如,我想使用 Firefox 在本地主机端口 8081 上启动“客户端服务器”,并使用 Chrome 在端口 8082 上启动“资源服务器”。客户端服务器应该能够向资源服务器发出请求以检索 json 数据。每个服务器都应该可以配置自己的设置。简而言之,我想做一些类似的事情
MyTestCase(LiveServerTestCase):
@override_settings(DATABASE={... client db config ...})
def launch_client(self):
self.client = webdriver.Firefox() # on port 8081
@override_settings(DATABASE={... resource db config ...})
def launch_resource(self):
self.resource = webdriver.Chrome() # on port 8082
def test_get_json(self):
self.client.get('http://127.0.0:8082/get/data/') # which should return data from the resource server ...
Run Code Online (Sandbox Code Playgroud)
到目前为止,我已经提出了以下解决方案,但这些解决方案不起作用:
最基本的:使用 LiveServerTestCase 同时启动两个网络驱动程序。IE
class MySeleniumTests(LiveServerTestCase):
@classmethod
def setUpClass(cls):
cls.selenium_chrome = webdriver.Chrome()
cls.selenium_firefox = webdriver.Firefox()
super(MySeleniumTests, cls).setUpClass()
Run Code Online (Sandbox Code Playgroud)但这不起作用,因为两个网络驱动程序将在同一端口上运行,并且不允许在每个服务器上进行不同的设置。
将 django鼻子与多进程选项一起使用( …
我尝试按照文档(https://docs.julialang.org/en/v1/manual/embedding/index.html)中的说明嵌入 Julia,但无法使其与字符一起使用。我可能错过了一些基本的东西。
当我运行以下代码时
jl_function_t *func = jl_get_function(jl_base_module, "uppercase");
char const *julia = "julia";
jl_value_t *argument = jl_box_char(*julia);
jl_value_t *ret = jl_call1(func, argument);
const char *unboxed = jl_string_ptr(ret);
// expecting "JULIA", getting an empty string
Run Code Online (Sandbox Code Playgroud)
未装箱的变量返回空。jl_box_char 似乎需要一个指针,因为它的参数必须是 uint32_t (https://github.com/JuliaLang/julia/blob/24f1316e91de029f71f636db23aced49156b44ad/src/julia.h#L1182)。
请注意,调用时字符已正确拆箱:
jl_value_t *ret = jl_eval_string("uppercase(\"julia\")");
const char *unboxed = jl_string_ptr(ret);
Run Code Online (Sandbox Code Playgroud)
任何想法?谢谢。
我尝试使用Docker和bash脚本(我使用Coreos)设置PostgreSQL从站。我尚未找到任何有效的方法.pgpass。
我知道我可以创建PGPASSWORD环境变量,但是出于安全原因(如此处所述,http://www.postgresql.org/docs/current/static/libpq-envars.html),我不希望这样做,并且因为每次使用recovery.conf文件时(对于primary_conninfo变量),都应该可以访问此密码。
Docker文件
# ...
# apt-get installs and other config
# ...
USER postgres
# Create role and db
RUN /etc/init.d/postgresql start &&\
psql --command "CREATE USER replicator WITH ENCRYPTED PASSWORD 'THEPASSWORD';" &&\
psql --command "CREATE DATABASE db WITH OWNER replicator;"
# Set the pg_pass to allow connection to master
ADD ./pgpass.conf /home/postgres/.pgpass # pgpass.conf comes my root git folder
USER root
RUN chmod 0600 /home/postgres/.pgpass
Run Code Online (Sandbox Code Playgroud)
在我的bash文件中
# ...
pg_basebackup -h host.of.master.ip -D /var/pgbackup/backup_data -U …Run Code Online (Sandbox Code Playgroud) 我在使用 psycopg2 和 SSL 建立两个并发 Postgres 数据库连接(一个到主数据库,一个到从数据库)时遇到问题。两个连接分别工作,即:
import psycopg2
dsnMaster='dbname=... sslcert=path/to/master/cert'
psycopg2.connect(dsnMaster, connection_factory=None, async=False)
Run Code Online (Sandbox Code Playgroud)
有效,也是如此
import psycopg2
dsnSlave='dbname=... sslcert=path/to/slave/cert'
psycopg2.connect(dsnSlave, connection_factory=None, async=False
Run Code Online (Sandbox Code Playgroud)
但同时加入两者
import psycopg2
dsnMaster='dbname=... sslcert=path/to/master/cert'
psycopg2.connect(dsnMaster, connection_factory=None, async=False)
dsnSlave='dbname=... sslcert=path/to/slave/cert'
psycopg2.connect(dsnSlave, connection_factory=None, async=False)
Run Code Online (Sandbox Code Playgroud)
第二次连接总是失败,带有SSL error: block type is not 01
. psycopg 似乎使用了之前连接的证书。
我尝试 .close() 第一个连接(如此处所示,但没有使用 psycopg2 动态在 python 中更改 ssl 数据库(postgresql)),并且还尝试了各种 psycopg.extensionsisolation_level 选项,但没有成功。
提前致谢!
我有一个带有装饰方法 (my_method) 的 Django 模型 (MyModel)。我希望装饰器对 my_method 执行一些检查:
如果检查成功,my_method 应该返回一个字符串;
如果检查不成功,my_method 应该返回装饰器返回的失败消息。
逻辑如下:
# models.py
class MyModel(models.Model):
@decorator1
@decorator2
def my_method(self, request, *args, **kwargs):
return u'The result that must be returned if all the checks performed by the decorator succeed'
# decorators.py
from functools import wraps
# decorator1 checks if certain conditions are met. If yes, it returns the decorated method (method_to_decorate); if not, it returns a tuple
def decorator1(method_to_decorate):
@wraps(method_to_decorate)
def wrapper1(self, request, *args, **kwargs):
if a_condition :
return …Run Code Online (Sandbox Code Playgroud)